简体   繁体   中英

Run .net web service with projects including both 32 and 64 bit assemblies

Is it possible to combine both 32bit and 64bit dlls in the same .net project? I get this error:

An attempt was made to load a program with an incorrect format

Indeed it is possible to add/use such assemblies in the same project.

What is not possible is to load assembly with mismatched architecture at run time, but that is relatively easy to handle in the code - check architecture an only use classes from corresponding assembly.

If you use only managed assemblies, specify Any CPU platform target.

If you use only native libraries from your project through [DllImport] - just include both to your project with different names, eg native.x86.dll and native.x64.dll , and select appropriate with similar code:

[DllImport("native.x86.dll")]
public static extern int ExtrernalFunc86();

[DllImport("native.x64.dll")]
public static extern int ExtrernalFunc64();
// ....
if (IntPtr.Size == 8) return ExternalFunc64();
else return ExternalFunc86();

If you use managed libraries which targeted to specific CPU (with same API), you can make reference to one of them, but copy both to output folder (with build script) and select appropriate version through AppDomain.CurrentDomain.AssemblyResolve event (check architecture using IntPtr.Size )

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