3

I've got a university project involves integrating Prolog with C# , So i downloaded the SwiPlCs DLL and linked it with my project.

I've got the following lines inside Main() method:

Environment.SetEnvironmentVariable("PATH", @"E:\\swipl\\bin");
string[] p = { "-q", "-f", @"test.pl" };
PlEngine.Initialize(p);

When i run the program , an exception occurs with the following message:

An unhandled exception of type 'System.BadImageFormatException' occurred in mscorlib.dll

Additional information:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

I spent all the time reading related questions on Stack Overflow , people were suggesting to change the platform target to x86 , and that's what i exactly did , but nothing worked and i'm still getting the same exception.

Are there any solution(s) to this problem ?

  • Did you see this [Q&A](https://stackoverflow.com/q/53877772/1243762)? – Guy Coder Dec 29 '18 at 23:14
  • If you could update your question with the exact steps you took so that we can recreate the problem it would help. When I say exact, I mean it needs to include the versions of every tool in the build chain, the configurations, the listings, etc. I would expect to see several pages of details listed here. If you want help than you have to help those helping you. There are not many people who can help you on this and if you make it hard for them your chance of getting help drops quickly. – Guy Coder Dec 29 '18 at 23:14
  • I've seen BadImageFormatException thrown when the .NET runtime couldn't load something that was built for a different version of the .NET CLR. SwiPlCs's CSPROJ file specifies a build target of .NET 2.0, so I'm suspicious of that. You might need to retarget your program for .NET 2.0.Another possibility to consider is that because it uses P/Invoke, the C# code must be compiled for the same architecture (32-bit x86 vs 64-bit x64) as the code it calls via P/Invoke. – Brian Rogers Dec 29 '18 at 23:57
  • One and a half year since i asked this question Nothing worked with me except trying it on the old computers in university Still i don't understand why it didn't work on mine – Eyad Mohammed Osama Jul 18 '20 at 20:30
  • probably because the DLL is a native x86 DLL, C# maybe expects a .NET CLR DLL (not CLR isn't native code but can still get put into a DLL or EXE) – Quonux Nov 15 '20 at 13:19

0 Answers0