简体   繁体   中英

DLLImport issues when changing target Dot net framework from 4.5 to 2.0

I want to compile my program to run on XP and dot net 2.0. I changed the target framework from 4.5 to 2.0 and removed "using System.Linq" and "using System.Threading.Tasks" from all files.

Now the DLLImport doesn't load and the program crashes when it get to the call. The error is "System.BadImageFormatException"

Prior to the framework downgrade the program worked.

Any ideas?

You need to check the platform of your native dll (x86 or x64). You can do that with the DUMPBIN utility:

dumpbin /headers yournative.dll

Check the machine header (x86 or x64)

Then you must compile to x86 or x64 your VS project (you can not use AnyCPU).

You can check the platform of your managed assembly with the CORFLAGS utility:

corflags yourmanaged.exe

Check the PE and the 32BIT headers (PE32 & 0: Any CPU, PE32 & 1: x86, PE32+ & 0: x64)

The two platforms must match.

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