NotSupportedException on il2cpp deserialize time.

Issue #368 open
Quan Yuan (quabug) created an issue
  1. What happened?
    NotSupportedException was throw at beginning.
    full log at the end.

  2. How can we reproduce it?
    Make a SerializedScriptableObject like below, build by il2cpp backend and run.

    public interface IMapSettings
    {
        List<Guid> Maps { get; }
        Dictionary<Guid, TextAsset> Files { get; }
        Dictionary<Guid, GameObject> Props { get; }
    }
    [CreateAssetMenu(fileName = "MapSettings", menuName = "Settings/MapSettings")]
    public class MapSettings : SerializedScriptableObject, IMapSettings
    {
        public List<Guid> Maps => _maps;
        public Dictionary<Guid, TextAsset> Files => _files;
        public Dictionary<Guid, GameObject> Props => _props;

        [SerializeField]//, ListDrawerSettings(OnBeginListElementGUI = "OnBeginMaps", OnEndListElementGUI = "OnEndMaps")]
        private List<Guid> _maps = new List<Guid>();

        [SerializeField, PropertyOrder(2)]
        private Dictionary<Guid, TextAsset> _files = new Dictionary<Guid, TextAsset>();

        [SerializeField, PropertyOrder(3)]
        private Dictionary<Guid, GameObject> _props = new Dictionary<Guid, GameObject>();
    }
  1. If screenshots would help explain or demonstrate your issue, please include these.
  2. What version of Unity are you using?
    Unity 2018.1.8f1 and 2018.2.0f2
    .Net 4 for both runtime and api
    il2cpp

  3. What version of Odin are you using? (See "Tools > Odin Inspector > About")
    could reproduce on both 1.0.6.9 and 2.0 beta

  4. Do you have Editor Only mode enabled?
    Nope.

  5. What operating system are you on?
    Windows standalone


NotSupportedException: C:\Program Files\Unity\Hub\Editor\2018.2.0f2\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.basic_init (System.Reflection.Emit.AssemblyBuilder ab) [0x00000] in <00000000000000000000000000000000>:0 
  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.Serialization.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.Serialization.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 'Services.View.Map.MapSettings': The type initializer for 'System.Reflection.Emit.DynamicMethod.AnonHostModuleHolder' threw an exception.

Comments (3)

  1. Tor Esa Vestergaard

    If you are building for Android or Windows using IL2CPP, you'll need to (for now) manually adjust Odin's assembly import settings, so that the NoEmitNoEditor assemblies are used for your target platforms, and the NoEditor assemblies are not. This is because Odin comes preconfigured with the assumption that people will, in general, use the non-IL2CPP backends for Windows and Android.

    The 2.0 release build will include a utility that does this for you automatically and ensures that Odin's assembly import settings are always set correctly for your target platform and runtime backend when you build.

  2. Log in to comment