Unable to load DLL in C#

30,776

Solution 1

Although the reader.dll is unable to load GPSVC.dll and IESHIMS.DLL. i managed to make it work by running the corflags command on application.exe the application is now marked as 32bit:


corflags application.exe /32bit+

Version : v4.0.30319

CLR Header: 2.5

PE : PE32

CorFlags : 3

ILONLY : 1

32BIT : 1

Signed : 0

Solution 2

If the problem is really "cannot be found", then using ProcMon from Sysinternals will show you where the system is looking for the DLL.

However, often these sort of exceptions mean 'I found the DLL but I can't load it', and that can be because a dependency of the DLL is missing rather than the DLL itself, or because the DLL is incompatible with the app trying to load it. If your C# app is set for 'Any CPU' and you're on a 64bit machine, you'll get this sort of error loading unmanaged 32-bit DLLs.

One way to isolate the problem would be to create a simple C/C++ project which loads the DLL. (Load it dynamically with LoadLibrary if you don't have access to the import lib.) Then use Dependency Walker to profile the test harness, and it will report the names of missing DLLs.

Solution 3

If it's a simple C DLL it just needs to be in the same folder as the .exe.

Solution 4

I found this in another post. Maybe it will help your situation

NUnit "missing" GPSVC.DLL on Windows 7/64

Share:
30,776
john
Author by

john

Updated on July 05, 2022

Comments

  • john
    john almost 2 years

    how to load a dll in a c# project

    error:

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

    code sample:

    [DllImport("Reader.dll")]
     public static extern byte OpenReader(ref IntPtr hCom, byte LinkType, string com_port);
    

    image: exception screenshot