Search Unity

NotSupportedException (With log detail)

Discussion in 'iOS and tvOS' started by jeffweber, Aug 3, 2018.

  1. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    I attempted to run my game on iOS and got the following crash. Any ideas what the problem could be or how I can try fixing the issue?
    Unity version: Unity 2018.2.1

    Log Text:
    2018-08-03 05:56:01.392329-0500 justflip[548:112091] Built from '2018.2/release' branch, Version '2018.2.1f1 (1a9968d9f99c)', Build type 'Release', Scripting Backend 'il2cpp'

    2018-08-03 05:56:01.394698-0500 justflip[548:112091] -> registered mono modules 0x1062014d0

    -> applicationDidFinishLaunching()

    -> applicationDidBecomeActive()

    GfxDevice: creating device client; threaded=1

    Initializing Metal device caps: Apple A11 GPU

    Initialize engine version: 2018.2.1f1 (1a9968d9f99c)

    Save game data

    PersistanceManager:Initialize()

    LoadGameState:Enter()


    (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)


    Serialize game state

    PersistanceManager:SaveGameData()

    LoadGameState:Enter()


    (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)


    NotSupportedException: /Users/builduser/buildslave/unity/build/External/il2cpp/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.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly (System.Xml.Serialization.XmlMapping[] xmlMappings, System.Type[] types, System.String defaultNamespace, System.Security.Policy.Evidence evidence) [0x00000] in <00000000000000000000000000000000>:0

    at System.Xml.Serialization.TempAssembly..ctor (System.Xml.Serialization.XmlMapping[] xmlMappings, System.Type[] types, System.String defaultNamespace, System.String location, System.Security.Policy.Evidence evidence) [0x00000] in <00000000000000000000000000000000>:0

    at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly (System.Xml.Serialization.XmlMapping xmlMapping, System.Type type, System.String defaultNamespace) [0x00000] in <00000000000000000000000000000000>:0

    at System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.String defaultNamespace) [0x00000] in <00000000000000000000000000000000>:0

    at PersistanceManager.SaveGameData () [0x00000] in <00000000000000000000000000000000>:0

    at LoadGameState.Enter () [0x00000] in <00000000000000000000000000000000>:0

    UnityEngine.UnhandledExceptionHandler:printException(String, Exception)

    UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)


    (Filename: currently not available on il2cpp Line: -1)


    justflip was compiled with optimization - stepping may behave oddly; variables may not be available.


     
  2. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Please try using the .NET Standard 2.0 Api Compatibity Level option. That .NET class library implementation should allow the XMLSerializer class to work correctly with the AOT restrictions on iOS. Starting in Unity 2018.3, either Api Compatibility Level option can be used.
     
    Ashsun and jeffweber like this.
  4. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I've been using XMLSerializer on iOS for many years without any issues.
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    This is a bug specific to the .NET 4.x Equivalent scripting runtime. XmlSerializer in general does work fine on iOS.
     
  6. Deleted User

    Deleted User

    Guest

    This also applies to Android (Unity 2018.2.17f building for Android 7.1)
    Scripting Runtime 4.x; IL2CPP; API Compat 4.x

    I added XMLSerializer and started getting a similar stacktrace via logcat.
    The funny part is that this does not occur, when building a "Development Build" Player with Script Debugging enabled.
    When building a non-development player, I receive a NotSupportedException regarding System.Reflection.Emit
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    That is rather odd, I don't think that script debugging should have an impact on this behavior.
     
  8. MohsenneChaverdie

    MohsenneChaverdie

    Joined:
    Nov 23, 2016
    Posts:
    39
    Pretty same thing happened to me working with System.ServiceModel.dll. I documented my issue on StackOverflow.
     
  9. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    Now, half a year later - this kind of major bug is known since half a year now - it's still present in Unity 2018.2.20. This really gives me the kicks! Everything works fine in the editor, and when you try to build the WebGL build, you get grounded hard. annoying as hell.
     
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Note that this should be corrected in Unity 2018.3. In Unity 2018.2 you will need to use the .NET Standard 2.0 Api Compatibility level to work around the problem.

    Are you seeing this issue with .NET Standard 2.0 in Unity 2018.2?
     
  11. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    Thank you! Setting back to .NET 2.0 Api fixed it for our release. Now looking forward to test it in 2018.3.
     
  12. JayArgh

    JayArgh

    Joined:
    Jul 23, 2013
    Posts:
    9
    @JoshPeterson I was experiencing a similar issue at runtime since updating from .NET 3.5 to 4.x:
    NotSupportedException: /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/AssemblyBuilder.cpp(20) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.

    We might not be ready for a 2018.3 upgrade just yet (it's a very large project), so I switched the API Compatibility to Standard 2.0 per your suggestion...and now I get an error at buildtime instead:
    `14035: [Unity] IL2CPP error for method 'System.Void Boo.Lang.Runtime.DynamicDispatching.Emitters.DispatcherEmitter::.ctor(System.Type,System.String)' in assembly '/BUILD_PATH/[projectname]/Temp/StagingArea/Data/Managed/Boo.Lang.dll'`
    `14036: [Unity] il2cpp.exe didn't catch exception: System.InvalidOperationException: attempting to call method 'System.Void System.Reflection.Emit.DynamicMethod::.ctor(System.String,System.Type,System.Type[],System.Type)' that does not exist`

    Any suggestions? :)
     
    Last edited: May 21, 2019
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    The first error (the one as runtime) indicates that IL2CPP does not support System.Reflection.Emit, which is expected. IL2CPP is an ahead-of-time (AOT) runtime, so it cannot emit dynamic code.

    The second error is a bit odd - I don't think that IL2CPP should error in this case.

    However the deeper issue is that the code in this project is trying to use System.Reflection.Emit with IL2CPP, which is not support (no matter what the Api Compatibility Level is). Can you determine what code in the project is trying to emit dynamic code?
     
  14. JayArgh

    JayArgh

    Joined:
    Jul 23, 2013
    Posts:
    9
    Searching the codebase itself, the only explicit references to System.Reflection.Emit are within platform-specific #if conditions that exclude UNITY_IOS. However, I do have a third-party plugin using System.Xml.Serialization's XmlSerializer - and the moment when it initializes is approximately the moment that the runtime error occurs.
     
  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Do you know if the third-party code is using XmlSerializer from the class libraries that Unity ships or from another implementation? The ones that Unity ships should be safe for AOT platforms. If there is some other assembly or implementation being used, that may not be the case.
     
  16. jtbentley

    jtbentley

    Joined:
    Jun 30, 2009
    Posts:
    1,397
    We're also getting a similar issue after moving to .Net 4.6 (Experimental) & IL2CPP in 2017.4.16, and it's also stemming from the in-built xml serialiser (wth a var serializer = new XmlSerializer call). The move was due to 64bit build requirements.
     
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Is it possible for you to try a newer version of Unity, maybe in the 2018.4 series? I wonder if this issue has been corrected in a newer version.
     
  18. Zapan15

    Zapan15

    Joined:
    Apr 11, 2011
    Posts:
    186
    We have also the same issue, using Unity 2019.2.0f1
     
    Sonorpearl likes this.
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Can you provide specific details about the error message you see in this case?
     
  20. Sonorpearl

    Sonorpearl

    Joined:
    Sep 8, 2017
    Posts:
    32
    Also getting the Error. Using Unity 2019.2.0f1. The newest version of the JSON .NET Port in the Assets Store. Compatibility set to .NET 4.X.
    Produces this error on build:
    Convert of JSON failed: System.Reflection.Emit.DynamicMethod::.ctor
     
  21. flkucho

    flkucho

    Joined:
    Feb 17, 2016
    Posts:
    1
    I had the same error building with IL2CPP for ARM64, finally this worked:
    Use Newtonsoft Json set to .NET 3.5 and added this to a link.xml file.

    <?xml version="1.0" encoding="utf-8" ?>
    <linker>
    <assembly fullname="System">
    <type fullname="System.ComponentModel.TypeConverter" preserve="all" />
    <!-- <namespace fullname="System.ComponentModel" preserve="all" /> -->
    </assembly>
    </linker>

    Hope this can help.

    The user Joshlmao uses it with his spotify4Unity asset
     
  22. X28

    X28

    Joined:
    Jul 15, 2015
    Posts:
    8
    I also have the same issue, using Unity 2018.4.9f1.
    It's a Run time error on the Android device.
    system.reflection.emit.dynamicmethod::ctor
    occurs when I want to save (or load) JSON data [with Newtonsoft.Json] to the PlayerPrefs.
     
    Last edited: Dec 1, 2019
  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    IL2CPP does not support JIT compilation on the device, so System.Reflection.Emit won't work. You will need to use a JSON converter that works with ahead-of-time (AOT) compilers.
     
    X28 likes this.
  24. Qmaks2

    Qmaks2

    Joined:
    Jun 2, 2012
    Posts:
    25
    JsonDotNet for Unity does not work with il2cpp, due to this bug.

    What can i use instead? To have access to JsonObject?
     
  25. Monica27

    Monica27

    Joined:
    Sep 1, 2020
    Posts:
    2
    I am getting the same exception on Unity 2019.4.11f1 if I am trying to run my app via IL2CPP (on Windows Player). I tried to change in build settings to use .NET Standard 2.0, but still the same exception.
    Here is the code I use for reflection:
    AssemblyBuilder dynamicAsm =
    AppDomain.CurrentDomain.DefineDynamicAssembly(asmName,
    AssemblyBuilderAccess.Run);
    dllModule = dynamicAsm.DefineDynamicModule(methodName+"_tempModule");
    // Dynamically construct a global PInvoke signature
    // using the input information
    MethodBuilder dynamicMethod = dllModule.DefinePInvokeMethod(
    methodName, dllPath, MethodAttributes.Static | MethodAttributes.Public
    | MethodAttributes.PinvokeImpl, CallingConventions.Standard,
    returnType, parameterTypes, CallingConvention.Winapi,
    CharSet.Ansi);
    What I am trying to do is to use a managed dll with my C# code which uses reflection to load a C++ dll. I can't use unity #define directives because the managed dll created via Visual Studio does not recognize them and I would prefer to have a single managed dll for all platforms. I must mention that the Visual Studio Library Class project was created with .NET Framework. I previously tried .NET Standard, but AssemblyBuilder.DefineDynamicAssembly is not supported on .NET Standard 2.0 and 2.1 is not supported by Unity yet. I also found another method via interopservices but needs .NET Core 3.1 also not supported by Unity.

    Am I missing something? Is there any other method that I can use so that I can run my app on multiple platforms and use the same managed dll to load different C++ dll (different name and different path depending on platform, architecture)?
     
  26. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Since IL2CPP is an ahead-of-time compiler, it does not support DefineDynamicAssembly, or any similar methods that create code at run time.

    I think your best bet to make this work is to have if checks at run time that determine the current platform and call the proper native code.
     
  27. Monica27

    Monica27

    Joined:
    Sep 1, 2020
    Posts:
    2
    Hi and thank you for your quick support! In fact, I am having if checks via Application.platform, but still need a method to import the c++ dll. I don't think I can use DllImport because I don't have a general name and path for the C++ dll.
     
  28. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    In that case, I don't have a good solution, sorry. I don't think this is something that you can easily do.
     
  29. wechat_os_Qy00eQZpMOQqPck_98OziwOak

    wechat_os_Qy00eQZpMOQqPck_98OziwOak

    Joined:
    Aug 1, 2020
    Posts:
    3
    when i use protobuf in unity webgl, there are some issues:
    (1)ProtoBuf.ProtoException: Get Method not found for 'Name' (NpcGenSen.NPCRequestInfo) ---> System.ArgumentException: Get Method not found for 'Name' at System.Reflection.MonoProperty.GetValue (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x00000] in <00000000000000000000000000000000>:0 --- End of inner exception stack trace --- at ProtoBuf.Meta.RuntimeTypeModel.GetKey (System.Type type, System.Boolean demand, System.Boolean getBaseKey) [0x00000] in <00000000000000000000000000000000>:0
    (2)System.InvalidOperationException: It was not possible to prepare a serializer for: NpcGenSen.NPCRequestInfo ---> System.NotSupportedException: System.Reflection.Emit.DynamicMethod::.ctor --- End of inner exception stack trace --- at ProtoBuf.Compiler.CompilerContext.BuildSerializer (ProtoBuf.Serializers.IProtoSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <00000000000000000000000000000000>:0

    Howerve,it works in editor
     
  30. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    It looks like some of the protobuf code is calling System.Reflection.Emit, which is not supported with IL2CPP or WebGL. I believe that it might be possible to use protobuf without run time code generation, but I'm not certain. Maybe check the protobuf documentation.
     
  31. Jackrohit

    Jackrohit

    Joined:
    Mar 29, 2019
    Posts:
    10
    Code (CSharp):
    1. NotSupportedException: System.Reflection.Emit.DynamicMethod::.ctor
    2.   at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Type owner, System.Boolean skipVisibility) [0x00000] in <00000000000000000000000000000000>:0
    3.   at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Type owner) [0x00000] in <00000000000000000000000000000000>:0
    4.   at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor[T] (System.Type type) [0x00000] in <00000000000000000000000000000000>:0
    5.   at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00000] in <00000000000000000000000000000000>:0
    6.   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00000] in <00000000000000000000000000000000>:0
    7.   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <00000000000000000000000000000000>:0
    8.   at System.Func`2[T,TResult].Invoke (T arg) [0x00000] in <00000000000000000000000000000000>:0
    9.   at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) [0x00000] in <00000000000000000000000000000000>:0
    10.   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <00000000000000000000000000000000>:0
    11.   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContractSafe (System.Type type) [0x00000] in <00000000000000000000000000000000>:0
    12.   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x00000] in <00000000000000000000000000000000>:0
    13.   at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <00000000000000000000000000000000>:0
    14.   at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <00000000000000000000000000000000>:0
    15.   at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <00000000000000000000000000000000>:0
    16.   at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <00000000000000000000000000000000>:0
    17.   at VideoManager+<Start>d__1.System.Collections.IEnumerator.Reset () [0x00000] in <00000000000000000000000000000000>:0
    18.   at System.Threading.Tasks.AsyncInfoToTaskBridge`1[TResult].CompleteFromAsyncOperationWithProgress[TProgress] (Windows.Foundation.IAsyncOperationWithProgress`2[TResult,TProgress] asyncInfo, Windows.Foundation.AsyncStatus asyncStatus) [0x00000] in <00000000000000000000000000000000>:0
    19.   at WebsiteData.<LoadCategoryData>b__11_0 (System.String response) [0x00000] in <00000000000000000000000000000000>:0
    20.   at UnityEngine.AudioClip+PCMReaderCallback.Invoke (System.Single[] data) [0x00000] in <00000000000000000000000000000000>:0
    21.   at WebsiteData+<GetSavedDataFromFile>d__15.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
    22.   at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
    23.   at UnityEngine.MonoBehaviour.StartCoroutine_Auto (System.Collections.IEnumerator routine) [0x00000] in <00000000000000000000000000000000>:0
    24.   at WebsiteData.Start () [0x00000] in <00000000000000000000000000000000>:0
    25. --- End of stack trace from previous location where exception was thrown ---
    26.   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
    27.   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    28.   at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    29.   at UnityEngine.WSA.WindowSizeChanged.BeginInvoke (System.Int32 width, System.Int32 height, System.AsyncCallback callback, System.Object object) [0x00000] in <00000000000000000000000000000000>:0
    30.   at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    31.   at UnityEngine.UnitySynchronizationContext.ExecuteTasks () [0x00000] in <00000000000000000000000000000000>:0
    32. UnityEngine.DebugLogHandler:LogException(Exception, Object)
    33. UnityEngine.Logger:LogException(Exception, Object)
    34. UnityEngine.Debug:LogException(Exception)
    35. UnityEngine.WSA.WindowSizeChanged:BeginInvoke(Int32, Int32, AsyncCallback, Object)
    36. UnityEngine.UnitySynchronizationContext:Exec()
    37. UnityEngine.UnitySynchronizationContext:ExecuteTasks()
    38. (Filename: currently not available on il2cpp Line: -1)
     
  32. Jackrohit

    Jackrohit

    Joined:
    Mar 29, 2019
    Posts:
    10
    Getting this error in Hololens
     
  33. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    System.Reflection.Emit is not supported with IL2CPP. You will need to use a JSON library that does not require use of it to work with Hololens. I believe that Newtonsoft JSON does have a mode that works with AOT runtimes like IL2CPP.