What should you do when the IL2CPP compiler starts striping your code from your external assemblies (dll) in you iOS builds. Causing your JSON De/serialization code to break.


1) Make sure you are using the Unity3d "tuned" version of JSON.Net. You can find the latest version here: Json.Net.Unity3D. This version does not make use of dynamic code - thus is "safe" for Ahead-of-time compilers.

2) Make sure you add the correct preservation lines into your Unity3D "link.xml" file:

<linker>
  <assembly fullname="AssemblyName.Common">
     <type fullname="AssemblyName.Common.*" preserve="all" />
   </assembly>
</linker>

The * will ensure that all namespaces as well as all classes are preserved - and will not be stripped.

That should do it.


Unless you are doing something really complicated you should be using Unity's built JsonUtility. Although it's good to know what's in this answer.

JsonUtility is very basic, i would recommend the exact opposite: you should only use it if you're doing something that is super simple.

lysergic-acid - I think you and Programmer are saying the same thing here. Over and above this - my original post was intended to focus more on the aggressive stripping that can occur using the IL2CPP compiler for AOT targeted builds. More about that here: link