简体   繁体   中英

AnyCPU C# DLL in 64bit process is unable to refer 64 bit C++ DLL(Giving error: Could not load file or assembly)

When I am providing 64bit C++ dll as a reference to a C# project which will generate AnyCPU C# dll. I am able to generate the C# dll but when I launch application An error comes saying,

Type : System.BadImageFormatException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxx Message : Could not load file or assembly 'MyDLLName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

As the C# dll is unable to fetch the C++ dll. So, how can I resolve this error?

You are trying to load a 64 bit library from a 32 bit process. Your C# dll can be AnyCPU, but the executing program has to be 64 bit to be able to load your C++ dll. In your project settings, check if you got the "prefer 32 bit" flag set and uncheck it - or simply build a 64 bit executable.

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