Error System.BadImageFormatException during importing LibreDWG.dll to C# code

0

I have created dll of LibreDWG using msys2 and swing, but I cannot import it to C# code.

Firstly, I compiled libreDwg using msys2:

$ ./configure --disable-python
$ make 

Then I applied swig to it and create dll using provided interface:

 $ swig -csharp dwg.i
 $ gcc -c -fpic *.c
 $ gcc -shared *.o  -o LibreDWG.dll

I have tried to import library to c# project using DllImport class:

     [DllImport("lib.dll", EntryPoint = "CSharp_dxf_cvt_lweight")]
     public static extern int dxf_cvt_lweight(short value);

        static void Main(string[] args)
        {
            try
            {
                var el = dxf_cvt_lweight(5);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
       }

But it throw an exception:

System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'

I checked dll using dumpbin tool and added dependencies: msys-2.0.dll and KERNEL32.dll to debug folder but error still occur.

c#
mingw
dllimport
msys2
libredwg
asked on Stack Overflow Feb 25, 2020 by Jarek Adamczyk

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0