Home > Software design >  How to solve the DLL cannot be found issue
How to solve the DLL cannot be found issue

Time:06-10

In my C# Wpf project, I need some funtion from C . So I make my own C DLL project named LibC. And the Wpf app can run normally in my computer. But on the tester's computer, the log says:

Unable to load DLL 'LibC.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

And I checked that the DLL file LibC.dll is there. By checking this post: Unable to load DLL (Module could not be found HRESULT: 0x8007007E)

Anthony Hayward's answer inspires me. So I run below dumpbin command and find that my dll rely on those 4 Window's dll. And on the tester's computer, two are missing: vcruntime140d.dll and ucrtbased.dll. While on my computer, all the four dlls can be found. So I copied the missing two dlls to the tester's computer, put them together with my LibC.dll, then the app works well now.

My question is how to solve this kind of problem in a better way? As I said, I copy the missing dll files manually to the tester's computer.

Another options is to put the two dlls into my project and release them together with my project files, including the exe file and LibC.dll.

Is it possible to statically link the two missing dll into my LibC.dll? Or any other advise?

"c:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\vc\Tools\MSVC\14.29.30133\bin\Hostx64\x64\dumpbin.exe" /DEPENDENTS libc.dll
Microsoft (R) COFF/PE Dumper Version 14.29.30143.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file libc.dll

File Type: DLL

  Image has the following dependencies:

    KERNEL32.dll
    USER32.dll
    VCRUNTIME140D.dll
    ucrtbased.dll

  Summary

        1000 .00cfg
        1000 .data
        2000 .idata
        1000 .msvcjmc
        3000 .pdata
        4000 .rdata
        1000 .reloc
        1000 .rsrc
        A000 .text
       10000 .textbss

CodePudding user response:

Your users will need to install the visual c runtime. The typical way to do this would be with an installer that does this silently. As far as I know they cannot be compiled into your program, and that the license prohibit distribution of lose dlls outside the redistribution package.

Note that you may need to update this package if you update the Visual studio version used to compile your dll.

Also note that you need to deploy the release build of your application, since the debug version of the dlls is only distributed as part of visual studio.

At last, that pure .Net code does not have these kinds of problems, so if you have c code it might be better to just rewrite it in c#. If you want to access some third party dll it might be better to use P/Invoke directly to that dll.

  • Related