September 16, 2020
Loading a VC++ .Net Framework DLL (likely be the case with other C++ DLLs) in .net core 3.1 fails with System.BadImageFormatException.
“The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid.”
They list the following probable causes:
The VC++ Dll had a dependency on nVida’s ONNX Runtime although all of its direct dependencies were present on of their dependencies had a different version. Reinstalling the environment resolved the issue.
If we try to load a VC++ .Net or native dll that has other native dependencies one of which is missing or has a different version than expected, we will get a System.BadImageFormatException. Be extra careful if the referenced dlls, SDK is driver dependent such as the Onnx runtime.