Search Unity

An exception of type 'System.TypeInitializationException' StartUp

Discussion in 'Windows' started by MrEsquire, Sep 18, 2016.

  1. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hi guys,

    EDIT: Thread Clean Up.

    I'm using freshly generated build using Unity 5.4.1patch1 and latest Visual Studio updates.
    Been trying to port my game to Xbox hence the needed update.

    Master Config With D3D

    ERROR:
    Code (CSharp):
    1. An exception of type 'System.TypeInitializationException' occurred in System.Private.CoreLib.dll but was not handled in user code
    2.  
    3. Additional information: TypeInitialization_Type_NoTypeAvailable
    4.  
    5. If there is a handler for this exception, the program may be safely continued.
    Any ideas what this means or if anyone else has issue?

    Thanks
     
    Last edited: Sep 19, 2016
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Does removing that code solve the problem?
    I can't spot anything wrong with it, so looks like a bug.
     
    MrEsquire likes this.
  3. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    After thinking about it, do not think code is issue, this code not been changed in previous versions of my game build and all worked.

    It could be a issue with latest Visual Studio build, has everything been upgraded on your side or known fixes coming next week.

    I also have issue on Xbox Only = An unhandled exception of type 'System.NullReferenceException' occurred in WinRTBridge.dll that I'm trying figure out what is causing it as this related to your side the specific .dll. Again could be related to not having latest updates (happens on 5.5beta also.)

    Any further thoughts?
     
    Last edited: Sep 19, 2016
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,676
    Are these exceptions first chance exceptions (you can continue past them) or do they take down the application?

    Do you have a stacktrace for them?
     
  5. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    The System.TypeInitializationException can bypass this one.
    The System.NullReferenceException' occurred in WinRTBridge.dll causes crash.

    I will try and get some more information, will check my coding first to see if I got everything set correctly before trying to officially file any bug reports..

    Just wanted know if anyone experienced similar or any known issues.. cheers
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,907
    When you hit System.TypeInitializationException , type $exception in watch window in Visual Studio, it may contain more info.
     
    MrEsquire likes this.
  7. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Yes there is a lot of extra information:

    This is the line I feel looks interesting.

    Stack Trace Text: (XXX = removed project file name for thread)

    StackTrace " at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(Void* returnValue, StaticClassConstructionContext* pContext) in f:\\dd\\ndp\\fxcore\\CoreRT\\src\\System.Private.CoreLib\\src\\System\\Runtime\\CompilerServices\\ClassConstructorRunner.cs:line 89\r\n at XXX.XXX() in C:\\Users\\XXX\\Desktop\\XXX\\Assets\\Scripts\\XXX.js:line 70\r\n at XXX.$Invoke3(Int64 instance, Int64* args)\r\n at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)" string
     
    Last edited: Sep 19, 2016
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    This comes from Unity generated code. It's either something not generated correctly/corrupted, or a bug.
    Do you get this error on a clean build?
     
  9. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732
    Build to an empty directory, to make sure there are no leftovers from previous builds. If it fails, please report a bug.
     
  10. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Ah okay, yes I did this - clean directly.

    So I reinstalled Unity and using back-end .NET + Use Net Core Partially (due to plugins used in project) D3D as mentioned already.

    The error still exists, so pretty sure maybe Unity issue as I see the output console also spammed alot with messages such as: C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\ARM\ilc\IlcInternals.targets(936,5): warning : ILTransform_0027: Invalid IL detected in method, although I think can ignore these.

    XboxOne: $exception this latest:

    StackTrace " at WinRTBridge.Utils.ThrowNewNullReferenceException(String message) in C:\\buildslave\\unity\\build\\PlatformDependent\\WinRT\\WinRTBridge\\Utils.cs:line 156\r\n at System.Action`1.InvokeOpenStaticThunk(T obj)\r\n at WinRTBridge.MethodTools_ThrowNewExceptionDelegate__WinRTBridge__Impl.ReverseDelegateStub(Byte* unsafe_message) in c:\\Users\\XXX\\Desktop\\XXX\\XXX\\obj\\x64\\Master\\ilc\\intermediate\\XXX.McgInterop\\ImplTypes.g.cs:line 80916" string
     
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,676
    ^ do you have a more full stacktrace for that null reference exception?
     
  12. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Apologies but is there a specific screen or section I need copy you from Visual Studio?
    Not sure what I need to be looking at as this was the line copied from $exception..
     
  13. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,676
    Yeah, there's a window called "Call stack".
     
  14. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Ok so after checking all code and update plugins, this is where I stand.

    We use XBOX ONE as example as both happen on this device:


    Exception 1: On Game Startup:

    Assembly-UnityScript.dll!xxx.FxxxPxxx() Line 70 C#
    Code: function FxxxPxxx():IEnumerator

    System.Private.CoreLib.dll!System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(void* returnValue, System.Runtime.CompilerServices.StaticClassConstructionContext* pContext) Line 88 C#


    Exception 2: On Game Scene Load - Error has changed slightly.

    Message Evaluation of method System.Exception.get_Message() requires use of the static field System.Text.StringBuilderCache.t_cachedInstance, which is not available in this context.string

    StackTrace " at WinRTBridge.Utils.ThrowNewNullReferenceException(String message) in C:\\buildslave\\unity\\build\\PlatformDependent\\WinRT\\WinRTBridge\\Utils.cs:line 156\r\n at System.Action`1.InvokeOpenStaticThunk(T obj)\r\n at WinRTBridge.MethodTools_ThrowNewExceptionDelegate__WinRTBridge__Impl.ReverseDelegateStub(Byte* unsafe_message) in c:\\Users\\xxx\\Desktop\\New folder\\xxx\\obj\\x64\\Master\\ilc\\intermediate\\XXXX.McgInterop\\ImplTypes.g.cs:line 80996" string

    This is what was on Stack Trace Window and not much more.
    I have a feeling they maybe Unity issues, please can you check your side and see if you can see any code issues... Not sure what next steps to take. Only thing I can try is the next Unity patch release..

    Cheers
     
  15. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,676
    Let's ignore the first exception and focus on the second one (since so far it seems that the first one is harmless).

    What happens when you continue on second exception? Don't you get another stacktrace?
     
  16. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hey dude,

    The first error seems to be related to .IEnumerators, as the first break was fixed by changing code not to use IEnumerator but then later in the game in another script issue came back. Is there any known bugs filed for this?

    For the second error I have fixed it by adding check to make sure the camera is not null. But I need to monitor this later in the game.

    Like I said before this is new issues due to 5.4 upgrade!
     
  17. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hey Tautvydas,

    Can you help on the first error, my fear is I cannot release my game as worried users may encounter this error and be stuck with it when playing, on visual studio we can bypass it.

    The error seems to be related to .IEnumerators, I assume this to be the case as the first break was fixed by changing code not to use IEnumerator - but then later in the game and through coding using it over 60 times, so cannot make a change to code.

    On visual studio I can bypass it by clicking continue.

    I provided you details start of thread? I cannot proceed at current level
     
    Last edited: Sep 24, 2016
  18. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
  19. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,676
    From what you said so far, it seems that it is an internal exception that is thrown and caught inside the .NET Framework. If you can continue in Visual Studio by pressing continue, it means it is a first chance exception and that it is fully handled. It's the same if you did this:

    Code (csharp):
    1. try
    2. {
    3.     throw new Exception("Oh hello there");
    4. }
    5. catch (Exception e)
    6. {
    7.    Debug.Log(e.Message);
    8. }
    Visual Studio would equally break on the throw statement, so you could inspect what caused the exception to be thrown. But, since it is handled, there's no harm in the exception itself.

    You can run your game without Visual Studio and without a debugger attached, and see if everything works fine. That should be confirmation enough that it will not make your game crash.
     
    MrEsquire likes this.
  20. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Thank you for reply, gives me some confidence.
    I still need to wait as I believe the random freeze error needs be fixed and still a few small issues with latest Unity and Windows 10, look forward to the bug fixes to come.
    Keep up good work, thanks..