Search code examples
c#dlldllimport

Unable to load DLL in C#


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


Solution

  • 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