简体   繁体   中英

Compile to x64 and received System.BadImageFormatException

I have a solution with a C# project of 'library' and a project 'JavaScript' after that compiled it generates a .winmd file being taken to another project. But this project is built on x86 and I need to compile for x64, to run the application in order x64 get the following error:

'WWAHost.exe' (Script): Loaded 'Script Code (MSAppHost/2.0)'. 
Unhandled exception at line 25, column 13 in ms-appx://2c341884-5957-41b1-bb32-10e13dd434ba/js/default.js
0x8007000b - JavaScript runtime error: An attempt was made to load a program with an incorrect format.
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
   at System.Runtime.InteropServices.WindowsRuntime.ManagedActivationFactory.ActivateInstance()
WinRT information: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
   at System.Runtime.InteropServices.WindowsRuntime.ManagedActivationFactory.ActivateInstance()
The program '[5776] WWAHost.exe' has exited with code -1 (0xffffffff).

If I understand you correctly, the 'library' project is compiled specifically to x86, and you are consuming it from the javascript project which is targeting x64?

If that is the case, you will not be able to make this work as the 64 bit process cannot load assemblies that are compiled for x86 explictily (you get the BadImageFormatException mentioned).

You options are to compiled the Javascript project in x86 mode, which will run on WoW, but I'm unsure how that relates to winmd files.

Your best bet is if you have access to the 'library' project code, to compile it as 'Any CPU' so it can be used by processes running in any bitness.

After some time, I found the problem. It is one of the dll's used possessed a method that had to be called problems, so it took was to identify . But to replace the DLL , the problem was solved .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM