Unity3d iOS中的Unity Json.net System.Reflection.Emit错误

Unity3d iOS中的Unity Json.net System.Reflection.Emit错误,unity3d,Unity3d,我按照说明将link.xml包含在资产文件夹中,但仍然出现错误。 我认为这可能与反序列化词典有关,因为错误发生在: System.Collection.Generic.IDictionary'2:set_Item(TKey, TValue). 看起来link.xml中有所有的转换器,但可能我遗漏了什么。这是指向link.xml的链接 这是堆栈: /Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/ical

我按照说明将link.xml包含在资产文件夹中,但仍然出现错误。 我认为这可能与反序列化词典有关,因为错误发生在:

 System.Collection.Generic.IDictionary'2:set_Item(TKey, TValue).
看起来link.xml中有所有的转换器,但可能我遗漏了什么。这是指向link.xml的链接

这是堆栈:

/Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/DynamicMethod.cpp(20) : Unsupported internal call for IL2CPP:DynamicMethod::create_dynamic_method - System.Reflection.Emit is not supported.   at System.Reflection.Emit.DynamicMethod.CreateDynMethod () [0x00000] in <filename unknown>:0 
  at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor[T] (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateDictionaryContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 
/Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/DynamicMethod.cpp(20):不支持对il2cpp的内部调用:DynamicMethod::create_dynamic_方法-System.Reflection.Emit。位于:0中的System.Reflection.Emit.DynamicMethod.CreateDynMethod()[0x00000]处
在:0中的System.Reflection.Emit.DynamicMethod.CreateDelegate(System.Type delegateType)[0x00000]处
位于:0中的Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor[T](System.Type类型)[0x00000]
在Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContact(Newtonsoft.Json.Serialization.JsonContract合同)[0x00000]中:0
位于:0中的Newtonsoft.Json.Serialization.DefaultContractResolver.CreateDictionaryContract(System.Type objectType)[0x00000]
位于:0中的Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(System.Type objectType)[0x00000]
位于:0中的Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(System.Type类型)[0x00000]
在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(Newtonsoft.Json.JsonReader,System.Type objectType,Boolean checkAdditionalContent)[0x00000]中:0
位于Newtonsoft.Json.JsonSerializer.DeserializeInternal(Newtonsoft.Json.JsonReader reader,System.Type objectType)[0x00000]中:0
在Newtonsoft.Json.JsonConvert.DeserializeObject(System.String值,System.Type类型,Newtonsoft.Json.JsonSerializerSettings设置)[0x00000]中:0
在Newtonsoft.Json.JsonConvert.DeserializeObject[T](System.String值,Newtonsoft.Json.JsonSerializerSettings设置)[0x00000]中:0

本例中的错误与托管代码剥离或link.xml文件无关。发生此错误的原因是Newtonsoft JSON库试图将
System.Reflection.Emit
与IL2CPP一起使用。IL2CPP不支持运行时代码生成,因此会显示错误消息


表示有一个版本的Newtonsoft JSON库可以与IL2CPP一起使用,但您可能想尝试它。

您可以使用Unity中的netstandard版本,它运行良好(至少在2018年及更高版本中)。该库似乎已将一些内部实现更改为不使用
System.Reflection.Emit

请查看详细信息

以下是一段摘录:

  • 在zip文件中,导航到lib/netstandard2.0目录并复制Newtonsoft.Json.dll文件。将Newtonsoft.Json.dll文件粘贴到Unity项目的插件目录中

  • 在Unity项目的资产目录中创建一个名为link.xml的文件,并添加以下xml。这将确保Unity的字节码剥离过程在导出到IL2CPP平台时不会删除必要的数据。虽然此步骤特定于此库,但以类似方式使用反射的其他库可能会遇到问题。有关更多信息,请参阅Unity关于此主题的文档

     <linker>
       <assembly fullname="System.Core">
         <type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
       </assembly>
     </linker>