BadImageFormatException in mscorlib.dll. The module was expected to contain an assembly manifest

1

i am trying to call some third party c# dll's from C++ program. In stand alone c# program everything works fine without exception. When running C++/CLI I get an exception "BadImageFormatException in mscorlib.dll" Could not load file or assembly "MyTestAppCpp.exe" or one of its dependencies. The module was expected to contain an assembly manifest.

For binding c# with c++ I am using c++ wrapper in C++/CLI. All settings in C++ programs, cpp wrapper and c# dll are 32bits. In ProcessExplorer Image Type of my application is 31-bit. Wow64.dll, wow64cpu.dll, wow64win.dll and nt.dll are 64-bit. Can this cause the problem? Answers in almost all posts about BadImageFormatException are that some settings are false and x86 and x64 are mixed. All settings seems to be correct. Somehow I couldn't find any suitable post how to fix the problem. What should be placed in manifest file in this case and how to create it for c++? Any other ideas how to fix the problem? The exception message appears only with attached debugger. When running application without debugger, no message box appears. Despite the exception, application seems to be working fine.

I am using Win 8.1, visual studio 2015.

EDIT: Thanks to answer from Hans Passant I started using Fuslogvw. Firstly there was a report that Serialization.dll(third party provider, not the microsoft .net one) couldn't be found. After copying this and all other dlls into /debug directory I got following error:

LOG: Assembly download was successful. Attempting setup of file: F:\Projects\MyTestAppCpp\Debug\MyTestAppCpp.exe.
LOG: Entering download cache setup phase.
ERR: Error extracting manifest import from file (hr = 0x80131018).
ERR: Setup failed with hr = 0x80131018.
ERR: Failed to complete setup of assembly (hr = 0x80131018). Probing terminated.

I've read a post about same problem(unfortunatelly I cannot find it any more) that c++ application cannot load manifest from .net dll's because of different format. Can it be the case here?

My another idea was that maybe it is a similar problem as with FileNotFound exception in .net for XMLSerialzer as in this post XmlSerializer giving FileNotFoundException at constructor

When ignoring the exception and continuning debugging in Modules window in VS I can see, that all dll's are loaded properly. The application seems to be working fine. Can I just ignore the BadImageFormatException in this case?

c#
c++
dll
c++-cli
asked on Stack Overflow Sep 6, 2017 by Martin • edited Sep 15, 2017 by Martin

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0