System.DllNotFoundException: Unable to load DLL 'Kernel32.dll': The specified module could not be fo

I’m trying to use the repo linked below in my UWP/HoloLens (1st gen) app and I get DllNotFoundException. The repo below does do [DllImport(“kernel32.dll”, SetLastError = true)]. I’ve seen other posts and the docs that say to do DllImport(“__Internal”) so I downloaded the repo and changed the code to [DllImport(“kernel32.dll”, SetLastError = true)] rather than kernel32.dll but got linking error during the build (Unity built the UWP project fine but building the app resulted in linking errors before it was ever deployed to the HoloLens).

Unity version 2018.4.8f1
My Api Compatibility Level is .NET Standard 2.0

Can someone help me solve the dll not found error, or tell me what I am doing is simply not possible? Thanks

I don’t think kernel32.dll doesn’t exist on HoloLens. Are you using .NET or IL2CPP scripting backend?

I’m using IL2CPP scripting backend.

As a separate test outside of Unity3d I created a UWP App, referenced the same dlls and deployed to the Hololens. I didn’t get any errors and the code worked correctly (encoding rgba values to a jpeg image). That made me think it was something in the conversion to IL2CPP.

If you’re using IL2CPP scripting backend, you can’t DllImport into system DLLs. It’s not supported. You have to use [DllImport(“__Internal”)] instead.

I saw using [DllImport(“__Internal”)] on another thread and in the Unity3d docs but I don’t understand how to use it. When I change from [DllImport(“kernel32.dll”, SetLastError = true)] to [DllImport(“__Internal”)] I get the error below when building the UWP solution output by Unity from the Build Settings menu. Is there something else I need to do?

LNK2019 unresolved external symbol _LoadLibraryEx@12 referenced in function _NativeModulesLoader_LoadLibraryEx_mE32AC2A0C539DD7CB186E920BCDA5941767F5A4C Il2CppOutputProject

LoadLibraryEx is not a supported API on UWP. See this (Minimum supported client Windows XP [desktop apps only]) LoadLibraryExW function (libloaderapi.h) - Win32 apps | Microsoft Learn

While it works outside of unity in an empty UWP app, that app will fail app certification and you will not be able to put it up on the Windows Store. IL2CPP catches these issues at build time instead.

@Tautvydas-Zilys Thank you very much for the help