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?

Martin
  • 83
  • 1
  • 9
  • Hmm, a third party DLL with the name "aaa.exe". That doesn't sound right, does it? Do make sure you don't have both a file named "aaa.exe" and "aaa.dll". .NET assemblies only have a display name, not a file name extension and unfortunately the CLR will look for an exe file before it tries to find a dll file. So if you meant to load aaa.dll then it will keel over when it finds aaa.exe since it is not a .NET assembly. And fail with BadImageFormatException. – Hans Passant Sep 06 '17 at 12:21
  • Hi, thanks for your message. "aaa.exe" was just an example, but you are right, that it doesn't sound good. I've changed it to original name(which is also not really good). I've checked it, but there are no multiple same names for exe and dll. – Martin Sep 06 '17 at 13:19
  • Sigh, obfuscating the *most* important detail of the question does not help us help you. Improve your question by adding the Fuslogvw.exe trace. – Hans Passant Sep 06 '17 at 13:20

0 Answers0