Is AnyCpu x64 link valid?

Is it a valid script to reference x64-dll from AnyCpu DLL when the system it will run on is probably a 64-bit system?

I am asking because I am having trouble getting an exception like this:

Could not load file or assembly 'XY' or one of its dependencies. An attempt was made to load a program with an incorrect format. "

I've had this problem multiple times with different solutions over the last couple of years. Sometimes it works and sometimes it doesn't.

+3


source to share


1 answer


For a build AnyCPU

for x64 target, DLL is perfectly valid. But you need to make sure that your build is AnyCPU

actually running as an x64 process.

Note that later versions of Visual Studio added a "Preferred 32-bit" option for assemblies. Therefore, you need to make sure that this is disabled and that you are not using any settings on the machine that would override this setting.



Also note that if your assembly AnyCPU

references other assemblies that can only be accessed as x86 assemblies on the target machine, it will run as an x86 process.

Honestly, if you know you only want the process to run as x64, IMHO it makes sense to compile it as x64

. At least if you exit in an incompatible environment, you will receive an error (i.e. the event log will contain information about the dependency that is incompatible with your process, not some other dependency, which is actually as expected) ...

+3


source







All Articles