none
Porting C# WPF application + C++(unmanaged )DLL from 32-bit Intel processor to 64-bit intel processor on VS2008 RRS feed

  • Question

  • Hi All,

    I am have various unmanaged C++ DLLs which are used as reference in C# WPF application. I have this code working very well and tested on 32-bit Intel processors.

    Now I am trying to run the application on 64-bit Intel processors. To compile C++ DLL code on 64-bit machine, I have added a new platform named "x64" which is for compilation on 64-bit machines. After doing this I am able to compile these DLLs successfully.

    I am using this C++ DLL in two different applications. One application is C++ application and other is C# WPF applications. These DLLs works very well with C++ application on both 32-bit and 64-bit platform but these applications don't work with C# on 64-bit.

    I get following exception when I try to run C# WPF application on 64-bit machine:
    "Could not load file or assembly 'objectclassbridge, Version=1.0.3491.32374, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format."

    objectclassbridge.dll is the DLL that acts as a bridge between unmanaged C++ code and Managed C# code.

    Please guide me to resolve this error.
     
    Regards!!!
    Thursday, July 23, 2009 1:22 PM

Answers

  • Sounds like you have some assemblies with x64 code, some with x86 code.  Neither setting will work.  Getting rid of the x86 dependency will be the harder problem, it is usually some kind of COM component for which you can't get an x64 version.  You'd be stuck at x86 until you do.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Wednesday, July 29, 2009 4:05 PM
    Friday, July 24, 2009 10:49 AM
    Moderator

All replies

  • Bad format exceptions usually occur when you try to load a 64bit dll into a 32 bit process or visa versa. see what happens when you put your solution platform of your C# application from any cpu to either x86 or x64 (and make sure it has the matching native dll's to work with)
    Thursday, July 23, 2009 2:27 PM
  • I confirmed this. I changed "Any CPU" option to x86. When I run the application, it saying invlalid Win32 DLL. So that confirms that the DLLs are generated for 64-bit. But when i change "Any CPU" to x64, it gives the same error.

    Please guide me on this.

    Friday, July 24, 2009 5:45 AM
  • Sounds like you have some assemblies with x64 code, some with x86 code.  Neither setting will work.  Getting rid of the x86 dependency will be the harder problem, it is usually some kind of COM component for which you can't get an x64 version.  You'd be stuck at x86 until you do.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Wednesday, July 29, 2009 4:05 PM
    Friday, July 24, 2009 10:49 AM
    Moderator
  • You could try turning on unmanaged debugging, with a bit of luck it'll spit the filename of the dll its loading in the output window shortly before you get your exception.
    Friday, July 24, 2009 1:49 PM