Search Unity

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

Discussion in 'Windows' started by af125, Oct 19, 2020.

  1. af125

    af125

    Joined:
    Aug 7, 2018
    Posts:
    4
    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).

    https://github.com/Sergey-Terekhin/...ster/libjpeg-turbo-net/NativeModulesLoader.cs

    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
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I don't think kernel32.dll doesn't exist on HoloLens. Are you using .NET or IL2CPP scripting backend?
     
  3. af125

    af125

    Joined:
    Aug 7, 2018
    Posts:
    4
    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.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    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.
     
  5. af125

    af125

    Joined:
    Aug 7, 2018
    Posts:
    4
    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
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
  7. af125

    af125

    Joined:
    Aug 7, 2018
    Posts:
    4