4

I followed the instruction and include the link.xml in the asset folder but I still get the error. I think it might be related to deserializing dictionaries since the error comes right after:

 System.Collection.Generic.IDictionary'2:set_Item(TKey, TValue).

It looks like the link.xml has all the converters in it but maybe I'm missing something. This is the link to the link.xml

Here's the stack:

/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 
jbassking10
  • 833
  • 4
  • 15
  • 42

2 Answers2

6

The error in this case is unrelated to managed code stripping or the link.xml file. This error occurs because the Newtonsoft JSON library is attempting to use System.Reflection.Emit with IL2CPP. Runtime code generation is not supported by IL2CPP, hence the error message.

This answer indicates there is a version of the Newtonsoft JSON library that will work with IL2CPP though, you may want to try it instead.

Community
  • 1
  • 1
Josh Peterson
  • 2,299
  • 19
  • 21
3

You can use netstandard version of Newtonsoft.Json in Unity and it works fine (at least in 2018 and higher versions). It seems that this library has changed some inner implementations to not use System.Reflection.Emit.

Look at this answer for details.

Here's an excerpt from microsoft article:

  • Within the zip file, navigate to the lib/netstandard2.0 directory and copy the Newtonsoft.Json.dll file. Paste Newtonsoft.Json.dll file into your Unity project's Plugins directory.

  • Create a file named link.xml in your Unity project's Assets directory and add the following XML. This will ensure Unity's bytecode stripping process does not remove necessary data when exporting to an IL2CPP platform. While this step is specific to this library, you may run into problems with other libraries that use Reflection in similar ways. For more information, please see Unity's docs on this topic.

     <linker>
       <assembly fullname="System.Core">
         <type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
       </assembly>
     </linker>
    
Shpand
  • 661
  • 9
  • 14