locked
BadImageFormatException after installing VS2010 SP1 RRS feed

  • Question

  • Hi, I have several WCF services and forms applications that call an Oracle database directly using System.Data.OracleClient. They have been working perfectly fine using 'Any CPU' as the platform. Yesterday, I installed Visual Studio SP1 and the updates for SP1 (this bit is important as I think it was working after SP1 install), and now every time I make a call to the database I get the dreaded:

    "Attempt to load Oracle client libraries threw BadImageFormatException.  This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."

    Now, I know that I can SOMETIMES get it working if I set the target platform to x86, but this isn't ideal as sometimes I will have 64bit binaries in the same project (like Sharepoint 2010), or I will deploy it to a server with 64bit Oracle installed or whatever. Also, I was sure I had 64bit version of Oracle client on my development machine but can't be sure.

    My WCF services if I set platform to x86 when I debug using WcfSvcHost throw 'WcfSvcHost encountered a critical error and must exit' and also 'System.BadImageFormatException: Could not load file or assembly [MyAssembly] An attempt was made to load a program with an incorrect format.

    Does anyone have any idea why this is?
    And also for bonus points, can anyone give me any advice as to what could go wrong if I just set the target platform to x86?

    Many thanks, Mike.



    Friday, October 28, 2011 9:43 AM

Answers

  • Hi Paul, thanks for the reply. It appears I have 32bit Oracle client on that particular development machine so it's anyones guess at how it was working before with 64bit libraries.

    However, I realised what I had done before the update was to set WcfSvcHost.exe to run in 32 bit mode by setting the parameter using CorFlags. This would explain why when I run the WCF client it gave me that error if I had the 32bit Oracle client installed, and also why it changed after the update - WcfSvcHost must have been overwritten in the service pack.

    The other problem I was having was with a console app which had the wrong target framework assigned.

    Hope my reply also can be helpful for anyone who has this problem.

    Cheers, Mike

    • Marked as answer by Allen_MSDN Tuesday, November 1, 2011 7:10 AM
    Monday, October 31, 2011 9:31 AM

All replies

  • An application cannot load both 32-bit and 64-bit libraries in the same memory space, so if you don't have a 64-bit Oracle client installed then you need to set the Platform option of your application to x86. You can have both 32-bit and 64-bit Oracle clients installed but they must reside in different ORACLE_HOME directories.

    It sounds to me like the app is running 32-bit but is attempting to load 64-bit libraries. If the app is dependent upon 64-bit libraries then you will definitely require a 64-bit Oracle client, and set the Platform option to Any CPU or x64.


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Friday, October 28, 2011 7:01 PM
  • Hi Paul, thanks for the reply. It appears I have 32bit Oracle client on that particular development machine so it's anyones guess at how it was working before with 64bit libraries.

    However, I realised what I had done before the update was to set WcfSvcHost.exe to run in 32 bit mode by setting the parameter using CorFlags. This would explain why when I run the WCF client it gave me that error if I had the 32bit Oracle client installed, and also why it changed after the update - WcfSvcHost must have been overwritten in the service pack.

    The other problem I was having was with a console app which had the wrong target framework assigned.

    Hope my reply also can be helpful for anyone who has this problem.

    Cheers, Mike

    • Marked as answer by Allen_MSDN Tuesday, November 1, 2011 7:10 AM
    Monday, October 31, 2011 9:31 AM
  • Hi Michael,

        Thank you for sharing your solution and experience here. It will be very beatiful fro other community members who have the similar problem. With your help, the forum will be better and better.

    Best Regards

     


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 1, 2011 2:33 AM