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

时间:2017-01-11 04:12:39

标签: 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/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 

2 个答案:

答案 0 :(得分:5)

此情况下的错误与托管代码剥离或link.xml文件无关。发生此错误的原因是Newtonsoft JSON库正在尝试将System.Reflection.Emit与IL2CPP一起使用。 IL2CPP不支持运行时代码生成,因此出现错误消息。

This answer表示有一个可以与IL2CPP一起使用的Newtonsoft JSON库的版本,你可能想尝试一下。

答案 1 :(得分:0)

您可以在Unity中使用Newtonsoft.Json的网络标准版本,并且工作正常(至少在2018年及更高版本中)。似乎该库已将某些内部实现更改为不使用System.Reflection.Emit

查看this answer了解详情。