Native library on UWP (ARM64, Hololens)

Viewed 259

For months I'm trying to pinvoke into a native DLL from C# running on a Hololens 2 (ARM64). The DLL is built from a Golang-library via CGO and Zig into a Windows-ARM64-DLL. I can confirm, that the DLL itself works as I have a basic StereoKit-based project, where the DLL works. My problems arise when UWP-Dlls come into play (means "get loaded"). This is all quite complex.

To reproduce my problem one could:

  1. Create a new empty UWP-Project for C#
  2. Deploy that to a Hololens 2 (device, not simulator) to prove it works
  3. Add the Nuget "uplink.Net" (the project still works on the device)
  4. Place the native DLL from here in the root-folder of the UWP-app - now the app crashes on startup.

The exception states something like "Exception happened in KernelBase.dll: Exception while Writing at position...".

Using native debugging I got this: enter image description here

Where I need help now is:

  1. Why does my DLL work on Hololens if no UWP-Dll is loaded?
  2. How could I trace the original error better? I have managed code available that once entered leads to the crash - so I could do some before-after-tracing. But all I found from this was a different set of loaded modules.
  3. Is there any kind of "step backward in time"-feature for Hololens-Deployments I could use? This blog mentioned a "time travel trace" using WinDbg. But I'm not sure if this is possible with remote debugging (via USB).

My guess here is: my native DLL contains the whole Go-runtime and the library (this is how CGO works). UWP on the other side has its own sandboxing stuff in place and I guess that collides with each other. But my low-level knowledge ends here. It might be some threading or memory-management-stuff that collides. Maybe Go starts some background threads that then are not allowed to run once UWP and its sandbox comes into play?

Any help is greatly appreciated! If test-repos are needed, let me know! I'm struggling with this thing for months now and already made so much progress (bringing a Go-library via CGO and Zig in a form that can be pinvoked from C# was a travel of its own). But now I'm stuck right in front of the finish-line.


Edit 01/14/2022: I've created a test-repo. Simply clone the repo and deploy it to a Hololens 2 (simulator would not work as the storj_uplink.dll-binary is for ARM64 only - a Surface Pro X might work, too, but this is not available here). https://github.com/TopperDEL/HololensTest

1 Answers
Related