NotSupportedException with il2cpp backend on 2018.1 Beta 9, SerializedScriptableObject

Issue #299 resolved
Former user created an issue

Hello. Using odin on the Mono backend works fine but causes an exception with il2cpp. (I also generated the DLLs before-hand)

NotSupportedException: C:\Program Files\Unity\Hub\Editor\2018.1.0b9\Editor\Data\il2cpp\libil2cpp\icalls\mscorlib\System.Reflection.Emit\AssemblyBuilder.cpp(20) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.
  at System.Reflection.Emit.AssemblyBuilder..ctor (System.Reflection.AssemblyName n, System.String directory, System.Reflection.Emit.AssemblyBuilderAccess access, System.Boolean corlib_internal) [0x00000] in <00000000000000000000000000000000>:0 
  at System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access, System.String dir, System.Security.Policy.Evidence evidence, System.Security.PermissionSet requiredPermissions, System.Security.PermissionSet optionalPermissions, System.Security.PermissionSet refusedPermissions, System.Boolean isSynchronized) [0x00000] in <00000000000000000000000000000000>:0 
  at System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Reflection.Emit.DynamicMethod+AnonHostModuleHolder..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] parameterTypes, System.Type owner, System.Reflection.Module m, System.Boolean skipVisibility, System.Boolean anonHosted) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Boolean restrictedSkipVisibility) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Utilities.EmitUtilities.CreateWeakInstanceFieldSetter (System.Type instanceType, System.Reflection.FieldInfo fieldInfo) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.GetCachedUnityMemberSetter (System.Reflection.MemberInfo member) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, Sirenix.Serialization.IDataReader reader) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, System.Byte[]& bytes, System.Collections.Generic.List`1[UnityEngine.Object]& referencedUnityObjects, Sirenix.Serialization.DataFormat format, Sirenix.Serialization.DeserializationContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, Sirenix.Serialization.SerializationData& data, Sirenix.Serialization.DeserializationContext context, System.Boolean isPrefabData, System.Collections.Generic.List`1[T] prefabInstanceUnityObjects) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, Sirenix.Serialization.SerializationData& data, Sirenix.Serialization.DeserializationContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.OdinInspector.SerializedScriptableObject.UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as TypeInitializationException: The type initializer for 'System.Reflection.Emit.DynamicMethod.AnonHostModuleHolder' threw an exception.
  at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] parameterTypes, System.Type owner, System.Reflection.Module m, System.Boolean skipVisibility, System.Boolean anonHosted) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Boolean restrictedSkipVisibility) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Utilities.EmitUtilities.CreateWeakInstanceFieldSetter (System.Type instanceType, System.Reflection.FieldInfo fieldInfo) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.GetCachedUnityMemberSetter (System.Reflection.MemberInfo member) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, Sirenix.Serialization.IDataReader reader) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, System.Byte[]& bytes, System.Collections.Generic.List`1[UnityEngine.Object]& referencedUnityObjects, Sirenix.Serialization.DataFormat format, Sirenix.Serialization.DeserializationContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, Sirenix.Serialization.SerializationData& data, Sirenix.Serialization.DeserializationContext context, System.Boolean isPrefabData, System.Collections.Generic.List`1[T] prefabInstanceUnityObjects) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.Serialization.UnitySerializationUtility.DeserializeUnityObject (UnityEngine.Object unityObject, Sirenix.Serialization.SerializationData& data, Sirenix.Serialization.DeserializationContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at Sirenix.OdinInspector.SerializedScriptableObject.UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as Exception: Exception thrown while deserializing type 'ItemScriptableObject': The type initializer for 'System.Reflection.Emit.DynamicMethod.AnonHostModuleHolder' threw an exception.

Comments (6)

  1. mSkull001

    Which platform is this compiled for?

    Depending on the platform we have the emitting enabled or disable by default. But emitting is not supported on the IL2CPP backend, so you'll manually have to change the DLL import settings. Unfortunately, Unity does not currently offer a way to configure the DLL import settings based on scripting backend.

    However, to get around this all you need to do is exclude the NoEditor DLLs and enable the NoEmitNoEditor DLLs instead.

    To do this, go to 'Plugins > Sirenix > Assemblies > NoEditor', select the Sirenix.Serialization and Sirenix.Utilities files in there and disable the platforms you're having issues with. Then select the Sirenix.Serialization and Sirenix.Utilities files in 'Plugins > Sirenix > Assemblies > NoEmitAndNoEditor' and enable the platforms on these DLLs.

    That should solve your issue :)

  2. Ivan Murzak

    Works for me too. But you need to make some tutorial in the FAQ on the landing page or somewhere in the section about AOT. Because I spent a lot of time before finding this issue. In my case, it was Android compilation with Scripting Runtime Version .NET 4.x. Equivalent, Api Compatibility Level .NET 4.x, Scripting Backend IL2CPP

  3. Log in to comment