[WSA] Exceptions in WinRTBridge.winmd and UnityEngineProxy.ni.DLL

Hi,

Please help me resolve runtime failures on Windows Phone 8.1!
Log output mentions some terrible messages: InvalidCastException in WinRTBridge.winmd, SEHException in UnityEngineProxy.ni.DLL, System.IO.FileNotFoundException in mscorlib.ni.dll. I’m not sure they are connected to each other, and don’t know what to do.

We have the game published in Windows Phone Store, built with Unity 4. Now we are migrating to WSA target platform in Unity 5.3.4f1 (on Windows 8.1 Pro). I use following settings:
• Scripting backend: .NET (not Il2Cpp)
• Compilation overrides: Use Net Core (not Partially)
• SDK: Phone 8.1 (not Universal yet)

After fixing a couple of compilation issues I’ve generated Windows Phone 8.1 project. In Visual Studio Community 2015 Update 1 I press [F5] (Start Debugging) to build, deploy and run on mobile device Lumia 920.

When specifying “Master” configuration, I get error messages mentioned above, execution stops after running for a while.

    '...' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.RUNTIME.INTEROPSERVICES.NI.DLL'. Symbols loaded.
    Exception thrown: 'System.InvalidCastException' in WinRTBridge.winmd
    Exception thrown: 'System.Runtime.InteropServices.SEHException' in UnityEngineProxy.ni.DLL
    Exception thrown: 'System.InvalidCastException' in WinRTBridge.winmd
    Exception thrown: 'System.Runtime.InteropServices.SEHException' in UnityEngineProxy.ni.DLL
    '...' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.XML.LINQ.NI.DLL'. Symbols loaded.
    '...' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.XML.NI.DLL'. Symbols loaded.
    Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.ni.dll
    The program '[5268] ...' has exited with code -2146233082 (0x80131506).

Debugger breaks on call to Resources.LoadAsync("MyPrefab") with message “An unhandled exception of type ‘System.ExecutionEngineException’ occurred in BridgeInterface.winmd”.

Running when “Release” configuratin is active provides more log entries:

    Exception thrown: 'System.InvalidCastException' in WinRTBridge.winmd
    Exception thrown: 'System.Runtime.InteropServices.SEHException' in UnityEngineProxy.ni.DLL
    SEHException: External component has thrown an exception.
    at UnityEngineProxy.InternalCalls.MonoBehaviour_CUSTOM_StartCoroutine_Auto(Object self, Object routine)
    at UnityEngine.MonoBehaviour.StartCoroutine(IEnumerator routine)
    at PromoActionsManager.Start()
    at PromoActionsManager.$Invoke56(Int64 instance, Int64* args)
    at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method) 
    (Filename: <Unknown> Line: 0)

    Exception thrown: 'System.InvalidCastException' in WinRTBridge.winmd
    Exception thrown: 'System.Runtime.InteropServices.SEHException' in UnityEngineProxy.ni.DLL
    SEHException: External component has thrown an exception.
    at UnityEngineProxy.InternalCalls.MonoBehaviour_CUSTOM_StartCoroutine_Auto(Object self, Object routine)
    at UnityEngine.MonoBehaviour.StartCoroutine(IEnumerator routine)
    at ChestBonusController.<GetEventBonusInfoLoop>d__0.MoveNext()
    at UnityEngine.Internal.$MethodUtility.$Invoke2167(Int64 instance, Int64* args)
    at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method) 
    (Filename: <Unknown> Line: 0)

When setting “Debug” configuration, the game runs a little bit longer, and outputs different error messages:

    Could not produce class with ID 148.
    (Filename: C:/buildslave/unity/build/Runtime/Serialize/PersistentManager.cpp Line: 1264)

    Dereferencing NULL PPtr!
    (Filename: c:\buildslave\unity\build\runtime\baseclasses\BaseObject.h Line: 1062)

It also complains about missing scripts, but I’ve double checked corresponding prefab, it’s ok:

    The referenced script on this Behaviour (Game Object 'Mark_Blue_Team') is missing!
    (Filename: C:/buildslave/unity/build/Runtime/Mono/MonoBehaviour.cpp Line: 1655)

    The referenced script on this Behaviour (Game Object 'Mark_Red_Team') is missing!
    (Filename: C:/buildslave/unity/build/Runtime/Mono/MonoBehaviour.cpp Line: 1655)

Please give me some clue on what is going on!

Thanks.

Do check in Debug configuration, it gives the most information and that information is much more accurate.

Don’t you get any errors about serialization problems? That might be one of the causes for this.
Also check for any UNITY_EDITOR macros in your scripts, perhaps there are editor fields?

Thanks for reply!

I tried when both “Development Build” in Unity and “Debug” configuration in Visual Studio were checked.

Unity reports some reference rewriter errors concerning third party dlls: “method ... doesn’t exist in target framework. It is referenced from Photon3Unity3D.dll at…”
But compilation succeeds.

The code base is very large, it’s hard to find public serialized fields that are excluded under specific platform defines. But there are no such issues on Andoid and iOS editions of our game, so it’s probably not the case of #if UNITY_EDITOR. Even if it is the case of missing field due to some preprocessor magic — error messages should not be so cryptic in that scenario.

ReferenceRewriter errors are not good. They usually indicate the problems that will come out at runtime or during submission (WACK failure). That’s where you should start fixing your project.

The problem with serialization is that WSA uses different implementation than iOS or Android, hence some corner cases can cause problems. Though I agree, that error messages are often not helpful, especially for large projects :frowning:

I agree with Aurimas. You need to fix ReferenceRewriter errors first. We don’t stop the build from completing, as in some cases the project might still work correctly. They tell you which classes and methods aren’t found during compilation, and if you do hit a path where they’re required at runtime, you’ll simply crash.

The debug build seems to crash for a different reason:

class ID 148 is “NetworkView”. It’s part of old networking APIs, which are no supported on Windows Store. Are you using any of classes from “UnityEngine.Network”? (note: UnityEngine.Networking is our new API, and is fully supported on Windows Store).

To clarify: one of your plugins must be using it, as scripts won’t compile with old networking APIs, they are not available on WSA.

Could you please extend this particular error message with actual class name in future release of Unity?

We are using legacy NetworkView for local multiplayer (with no dedicated server), and Photon networking for worldwide multiplayer. Local multiplayer is supported on Android and iOS (and Editor); and is not available on Windows Phone 8. All our usages of NetworkView are wrapped with conditional compilation; for third party libraries there were Plugins/WP8/*.dll stubs — this is how it used to work on old WP8 target before migration to WSA.

As far as I understood, new Unity networking does not support local multiplayer, does it?


Ok, thanks for clarification! I will try.

I suppose we should do that. Until we implement it, you can look at this page to get the name from class id:

http://docs.unity3d.com/Manual/ClassIDReference.html

1 Like

It does, but server and client has to run on different devices.

I fixed reference rewriter errors and got green WACK test result. But runtime errors are still there:

Could not produce class with ID 148.
Dereferencing NULL PPtr!

Could you please suggest what to attempt next?

Check you plugin settings and make sure you don’t have NetworkView used anywhere in you scripts on WSA.

All usages of NetworkView on WSA usually imply compile-time errors (so I fix them wrapping in conditional compilation). But I’m facing runtime errors at the moment.

Are you sure none of your plugins uses it?


I'm not, but both reference rewriter and WACK do not complain about missing types anymore.

NetworkView can also be a component on a gameobject. Is there any chance you have that on any of your prefabs or in your scenes? Does it crash when you try to load a particular scene?

Could we get a bug report on this? Even if you do have it in your scene somewhere, the error message is terrible and doesn't help you fix it in any way. I'd like to address it.

1 Like

Thanks; you are right. After removing NetworkView’s from prefabs Unity runtime stopped complaining about “Could not produce class with ID 148.” I used to perform such cleaning before, but in previous version of Unity this was build-time issue, not runtime; so it was easier to not to miss it. The Editor script for cleaning (in case if someone also encounters such a problem):

// Make sure prefabs are stored under version control so destructive changes can be discarded.

var guids = AssetDatabase.FindAssets("t:prefab", null);
var paths = guids.Select<string, string>(AssetDatabase.GUIDToAssetPath);
foreach (var path in paths)
{
    var go = AssetDatabase.LoadMainAssetAtPath(path) as GameObject;
    if (go == null)
        continue;

    var nvs = go.GetComponentsInChildren<NetworkView>(true);
    if (nvs == null || nvs.Length == 0)
        continue;

    Debug.Log(path);
    foreach (var nv in nvs)
        DestroyImmediate(nv, true);
}

AssetDatabase.SaveAssets();

However, there are still repeating NREs to be investigated:

NullReferenceException: Exception of type 'System.NullReferenceException' was thrown.
   at WinRTBridge.Utils.ThrowNewNullReferenceException(String message)
   at UnityEngineProxy.InternalCalls.GameObject_CUSTOM_GetComponent(Object self, Type type)
   at UnityEngine.GameObject.GetComponent[T]()
   at WeaponBonus.Start()
   at WeaponBonus.$Invoke2(Int64 instance, Int64* args)
   at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)

It mentions our method WeaponBonus.Start() but both start and end of stacktrace are inside Unity code. NullReferenceException is supposed to indicate callee-side error, not caller-side.

Can you enable break on exception in Visual Studio (Debug → Windows → Exception Settings, then check “Common Language Runtime Exceptions” checkbox), then turn on mixed mode debugging (Right click on VS project in solution explorer → Properties → Debug → Debugger type → Mixed), run your application and wait for the exception to happen? When it does, you should be able to see the full callstack including the native frames. Could you paste it?

Could you also specify, what type are you using when calling GetComponent from WeaponBonus.Start, maybe it’s one of the unsupported Network types?

Visual Studio says it does not allow to use mixed mode when running on device. (I can turn on this mode, but attempt to run debugging results in error message box.)

That was an issue with our logic. Maybe GameObject.FindGameObjectWithTag("...") in case of absence returns not null reference, but rather “pseudo-null” object. That’s why calling GetComponent<T>() on it resulted in NullReferenceException was risen not from our code but deeper in backtrace.

Anyway I fixed this particular issue (and moved on to bunch of new porting issues).

Thanks!

Sorry about that, I didn’t realize you were debugging on device. VS was correct: mixed mode debugging doesn’t work on ARM.