Question

I have a project which configured for "Any CPU". Now I have to refer a third party dll which has x86 and x64 compiled versions seperately(I cant get AnyCPU version of third party dll). I have changed the configuration file of my project to refer particular dll based on the platform as shown below.(This is a sample project config file)

<PropertyGroup>
<CurrentPlatform>x86</CurrentPlatform>
<CurrentPlatform Condition="'$(PROCESSOR_ARCHITECTURE)'=='AMD64' or '$(PROCESSOR_ARCHITEW6432)'=='AMD64'">x64</CurrentPlatform>
</PropertyGroup>
<ItemGroup Condition=" '$(Platform)' == 'x86' ">
<!--Compiled as ClassLibrary target platform is x86-->
 <Reference Include="ClassLibrary">
    <HintPath>..\..\ClassLibrary_x86\ClassLibrary_x86\bin\Debug\ClassLibrary.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(Platform)' == 'x64' ">
 <!--Compiled as ClassLibrary target platform is x64-->
 <Reference Include="ClassLibrary">
      <HintPath>..\..\ClassLibrary_x64\ClassLibrary_x64\bin\Debug\ClassLibrary.dll</HintPath>
</Reference>
</ItemGroup>

when I run this project in Visual studio it is not working. throwing BadImageException. When I change My project target platform to x86 and run the application it will work. If I change it to x64 then throw the same BadImageException.

What is the wrong here? I don't want to create two projects(x86 and x64) just because of one dll reference. Is there any other way to proceed if the above way is wrong?

My Dev environment is VS2010 and .NET4.0 and Win7 64bit OS.

No correct solution

OTHER TIPS

Change the platform option to be X86 and only reference the 32-bit dll. This way, the executable will run both on 32-bit and 64-bit OS. Application built with x86 option will run as 32-bit process on 64-bit OS under WOW64.

Also the next link can help - Conditionally use 32/64 bit reference when building in Visual Studio

The next link show how to load the right dll which is what you are looking for

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top