An exception of type 'System.TypeInitializationException' StartUp

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:

An exception of type 'System.TypeInitializationException' occurred in System.Private.CoreLib.dll but was not handled in user code

Additional information: TypeInitialization_Type_NoTypeAvailable

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

Does removing that code solve the problem?
I can’t spot anything wrong with it, so looks like a bug.

1 Like

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?

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?

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

When you hit System.TypeInitializationException , type $exception in watch window in Visual Studio, it may contain more info.

1 Like

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

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?

Build to an empty directory, to make sure there are no leftovers from previous builds. If it fails, please report a bug.

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

^ do you have a more full stacktrace for that null reference exception?

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…

Yeah, there’s a window called “Call stack”.

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

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?

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!

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

Similar issues: http://forum.unity3d.com/threads/system-typeinitializationexception-at-appcallbacks-setbridge-_bridge.376591/?_ga=1.117350534.1260769982.1474618081

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:

try
{
    throw new Exception("Oh hello there");
}
catch (Exception e)
{
   Debug.Log(e.Message);
}

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.

1 Like

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…