我无法让应用程序使用完整链接。这是我的设置(我的程序集名称已更改):
- 适用于 Android 4.4.54 的单声道
- 一个 Android 应用程序 ( MyApp )
- 与平台无关的库 ( MyLib )
我正在尝试使用 ServiceStack.Text 从 JSON 文本中反序列化一个类型(Person)。仅链接 SDK 程序集时它工作正常。
我没有将链接器包含属性放在MyLib中,而是在MyApp中使用LinkDescription XML 文件。它看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="MyLib">
<type fullname="MyLib.Person" preserve="fields">
<method name=".ctor" />
</type>
</assembly>
</linker>
这是我的 logcat 输出:
E/MyApp(14494): InitialiseUser(): System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.Text.Json.JsonReader`1 ---> System.ArgumentNullException: Argument cannot be null.
E/MyApp(14494): Parameter name: method
E/MyApp(14494): at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x00000] in <filename unknown>:0
E/MyApp(14494): at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0
E/MyApp(14494): at ServiceStack.Text.PlatformExtensions.MakeDelegate (System.Reflection.MethodInfo mi, System.Type delegateType, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0
E/MyApp(14494): at ServiceStack.Text.Json.JsonReader.GetParseFn (System.Type type) [0x00000] in <filename unknown>:0
E/MyApp(14494): at ServiceStack.Text.Json.JsonTypeSerializer.GetParseFn (System.Type type) [0x00000] in <filename unknown>:0
E/MyApp(14494): at ServiceStack.Text.Common.TypeAccessor.Create (ITypeSerializer serializer, ServiceStack.Text.TypeConfig typeConfig, System.Reflection.PropertyInfo propertyInfo) [0x00000] in <filename unknown>:0
E/MyApp(14494): at ServiceStack.Text.Common.DeserializeTypeRef.GetTypeAccessorMap (ServiceStack.Text.TypeConfig typeConfig, ITypeSerializer serializer) [0x00000] in <filename unknown>:0
E/MyApp(14494): at ServiceStack.Text.Common.DeserializeType`1[ServiceStack.Text.Json.JsonTypeSerializer].GetParseMethod (ServiceStack.Text.TypeConfig typeConfig) [0x00000] in <filename unknown>:0
E/MyApp(14494): at ServiceStack.Text.Common.JsReader`1[ServiceStack.Text.Json.JsonTypeSerializer].GetCoreParseFn[Person] () [0x00000] in <filename unknown>:0
E/MyApp(14494): at ServiceStack.Text.Common.JsReader`1[ServiceStack.Text.Json.JsonTypeSerializer].GetParseFn[Person] () [0x00000] in <filename unknown>:0
E/MyApp(14494): at ServiceStack.Text.Json.JsonReader`1[MyLib.Person]..cctor () [0x00000] in <filename unknown>:0
E/MyApp(14494): --- End of inner exception stack trace ---
E/MyApp(14494): at ServiceStack.Text.JsonSerializer.DeserializeFromString[Person] (System.String value) [0x00000] in <filename unknown>:0
E/MyApp(14494): at MyLib.Person.FromJson (System.String json, Boolean throwOnNullOrEmpty) [0x00000] in <filename unknown>:0
E/MyApp(14494): at MyApp.MainActivity.InitialiseUser () [0x00000] in <filename unknown>:0
在此之后,我的 Person 实例为空。
从输出中似乎找不到 Person 的默认构造函数(它没有明确定义的构造函数)。
任何帮助深表感谢。