Jon Tackabury
Jon Tackabury

Reputation: 49289

Unable to load C++ DLL in C# application in Vista x64

I have a DLL written in C++ that needs to be used by an application in C#. It works great under Vista x86, but under x64 it fails to load. So I build an x64 version of the DLL and I detect whether the OS is x86 or x64 and use the appropriate interop call to the appropriate DLL. This works fine under Vista x86, but under Vista x64 I get a "side-by-side" error when it tries to load the DLL. Why exactly is it failing to load it, and what can be done to correct this? (Please let me know if you need more information, I'm not sure what information is relevant in trouble-shooting this issue.)

Upvotes: 1

Views: 2798

Answers (5)

Dirk Vollmar
Dirk Vollmar

Reputation: 176239

some further information to the answer of MadKeithV:

In Windows x64 a process may be started as 32bit or 64bit process. A 64bit process can only load 64bit dlls and a 32bit process only 32bit dlls.

If your platform target (e.g. specified in the project properties) of your .Net application is set to "Any CPU", the intermediate code will be compiled to 32bit or 64bit code depending on the target platform, i.e. on a x64 system 64bit code will be generated.

Therefore the code can no longer load a 32bit dll.

If your code loads unmanaged assemblies you should always specify the target platform explicitly.

Upvotes: 3

Joel Lucsy
Joel Lucsy

Reputation: 8706

The redist for VC90 for x64 will need to be installed on the client machine. As far as the manifest goes, I think you can alter it to remove the processorArchitecture tag. Either that or have it say "any".

Upvotes: 2

Gishu
Gishu

Reputation: 136663

If nothing else works.. you can give Process Monitor a try. It shows you which file (dependency) was not found.. this may give you a lead to proceed.

Upvotes: 2

Aaron Fischer
Aaron Fischer

Reputation: 21231

The side by side error is more then likely caused by you c++ dll manifest file settings either they are not getting embedded or you have chosen to not embed the manifest and is using the 32bit versions manifest.

The simple solution is to mark your c# application as for the x86 cup and run with the 32bit dll.

Upvotes: 0

Joris Timmermans
Joris Timmermans

Reputation: 10988

One first idea: Could you try setting the "Platform Target" setting in the C# part of the project to "x86", to see if it will run in 32-bit compatibility mode on the Vista 64 machine?

More information about the SxS error would be useful - it might be related to some specific (32-bit?) versions of the runtime libraries that are not installed?

Upvotes: 4

Related Questions