Search code examples
c#c++unity-game-enginesignalril2cpp

Unity for UWP: An invalid handle was specified


I built my game for UWP with Il2Cpp. When it tries to connect to the internet I get this error:

Exception thrown at 0x2121FE8A in game.exe: 0xC0000008: An invalid handle was specified.

Since the C# source turned into a C++ project I've no idea what's wrong in my code. it works errorless when I play in Unity.

How can I find a clue on what's going wrong?

Screenshot:

enter image description here


Solution

  • I would not directly debug in the c++ generated code ... it is very intransparent and hard to interpret (also the Manual doesn't really help here)

    Rather build and deploy the app with the option Wait for Managed Debugger enabled and connect a Debugger in the c# VisualStudio solution (source)

    1. Set up your Unity project build settings and enable Development Build, Script Debugging and Wait for managed debugger

      enter image description here

    2. Build in Unity, open the solution in VisualStudio instance and deploy it to a remote device

    3. The build and deploy takes considerably longer and once deployed you're asked to attach the debugger

      enter image description here

    4. Open any script in VisualStudio from within Unity (so you have the entire solution loaded correctly) and select Attach Unity Debugger from the drop down

      enter image description here

    5. You should be prompted with a window that allows you to select the lens. (It should also work when the lens is attached via USB, but you might need to enable inbound UDP communication for devenv.exe)

      enter image description here

    On this way you can debug your normal c# code, set breakpoints etc. while it is actually running the Il2CPP generated c++ code.