When using the Gurobi .NET API, you may see a Bad Image Format Exception (System.BadImageFormatException) the first time you access the Gurobi .NET assembly.
The Gurobi .NET assembly (e.g. gurobiXX.NET.dll) is compiled for AnyCPU (64-bit preferred). Your application needs to ensure that the proper native library (gurobiXX.dll) is used at runtime for the target platform.
A BadImageFormatException occurs if you mix 32/64 bit libraries at the moment when the .NET runtime loads the native library. At runtime, each .NET application is JIT compiled to either a native x64 or x86 application depending on the system. For applications where it is necessary to use native libraries (like with Gurobi), we recommend explicitly creating and using the x64 and x86 build configurations and removing "AnyCPU" build configurations in Visual Studio.
Please sign in to leave a comment.