I have two 3rd party assemblies. One is compiled for x86 target, another one - for ANY CPU. Is there a way to use them from the same application.
Now my application is compiled successfully but fails to run. I tried to build my EXE file for both x86 and Any CPU but no luck. I could use corflags to change the target platform bits, but the assemblies are signed and I do not want to change their signature.
Could anyone help?
You can reference them - but the application will only run if the entry .exe assembly is set to x86 or it's set to Any CPU and run on an x86 machine. In the case of IIS-hosted processes, then the bitness is determined by IIS itself.
By way of example - I've just created this vs2010 solution: https://docs.google.com/open?id=0Bw_NnV9fhgmgSGxGOEZXSnVsd1k
The console app can be x86/Any APU and references two libraries - one that is x86 and one that is Any CPU.
If you set the exe to x86 and run it on x64 then it works fine (obviously it works on x86 no problems). If, however, you set the exe to Any CPU and run it on x64 it will crash (with a BadImageFormatException
). Again, running it on x86 will still work.
It's the flavour of the entry assembly that determines the bitness of the process; and therefore the expected bitness of any assemblies that can be loaded.
In your case, It's possible that the assemblies you're focussing on aren't necessarily the problem - it's assemblies that they reference. The exception might tell you more.