none
WCF Service Error Bad Image Format Exception on x86

    Question

  • I tried to place the 32 bit dll in Bin directory and also SYSWOW64 dir.

    The problem is when i run in "Any CPU" mode .. i get error while initializing the 32 bit dll and when i change the Platform Target to x86 i get the following error.

    Note: This is WCF Service which i am running and i get this error when i try to start with Default Client for WCF Service "WcfTestClient.exe".

    "

    System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\CShah\Documents\Visual Studio 2010\Projects\SilverLight\SSQueueServiceLibrary\bin\Debug\SSQueueServiceLibrary.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    File name: 'file:///C:\Users\CShah\Documents\Visual Studio 2010\Projects\SilverLight\SSQueueServiceLibrary\bin\Debug\SSQueueServiceLibrary.dll'
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
    at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)

    === Pre-bind state information ===
    LOG: User = CShah
    LOG: Where-ref bind. Location = C:\Users\CShah\Documents\Visual Studio 2010\Projects\SilverLight\SSQueueServiceLibrary\bin\Debug\SSQueueServiceLibrary.dll
    LOG: Appbase = file:///C:/Users/CShah/Documents/Visual Studio 2010/Projects/SilverLight/SSQueueServiceLibrary/bin/Debug
    LOG: Initial PrivatePath = NULL
    Calling assembly : (Unknown).
    ===
    LOG: This bind starts in LoadFrom load context.
    WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
    LOG: Using application configuration file: C:\Users\CShah\Documents\Visual Studio 2010\Projects\SilverLight\SSQueueServiceLibrary\bin\Debug\SSQueueServiceLibrary.dll.config
    LOG: Using host configuration file:
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Attempting download of new URL file:///C:/Users/CShah/Documents/Visual Studio 2010/Projects/SilverLight/SSQueueServiceLibrary/bin/Debug/SSQueueServiceLibrary.dll.
    ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated."I am getting an error Bad Image Format Exception when i change the Platform Target to x86 from Any CPU.
    It doesn't throw an exception when running on "Any CPU" as Platform Target.

    My OS is Win 7 x64. I figured out that as 64-bit framework being used, it is throwing the exception.
    "LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config."

    Now the problem is i am using Sybase database and i have a 32-bit dll and not x64.
    So if "Any CPU" is selected and i run the service, i am getting exception for memory location just while i create a connection object.
    AseConnection oAseCon = new AseConnection(str);

    Is there a solution that i can run a 3rd party 32-bit dll in a WCF Service on 64 bit machine.

    Help would be appreciated.

    Thanks .

    Wednesday, March 28, 2012 1:15 PM

Answers

  • If you build your WCF service in x86 mode, then the host should also be built in x86 mode. Check whether your WCF Service host is built in Any CPU mode. If yes, build it in x86 mode instead.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by Yi-Lun Luo Tuesday, April 03, 2012 9:12 AM
    Wednesday, March 28, 2012 4:36 PM

All replies

  • I am getting an error Bad Image Format Exception when i change the Platform Target to x86 from Any CPU.
    It doesn't throw an exception when running on "Any CPU" as Platform Target.

    My OS is Win 7 x64. I figured out that as 64-bit framework being used, it is throwing the exception.
    "LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config."

    Now the problem is i am using Sybase database and i have a 32-bit dll and not x64.
    So if "Any CPU" is selected and i run the service, i am getting exception for memory location just while i create a connection object.
    AseConnection oAseCon = new AseConnection(str);

    Is there a solution that i can run a 3rd party 32-bit dll in a WCF Service on 64 bit machine.

    Help would be appreciated.

    Thanks .

    I tried to place the 32 bit dll in Bin directory and also SYSWOW64 dir.

    The problem is when i run in "Any CPU" mode .. i get error while initializing the 32 bit dll and when i change the Platform Target to x86 i get the following error.

    Note: This is WCF Service which i am running and i get this error when i try to start with Default Client for WCF Service "WcfTestClient.exe".

    "

    System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\CShah\Documents\Visual Studio 2010\Projects\SilverLight\SSQueueServiceLibrary\bin\Debug\SSQueueServiceLibrary.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    File name: 'file:///C:\Users\CShah\Documents\Visual Studio 2010\Projects\SilverLight\SSQueueServiceLibrary\bin\Debug\SSQueueServiceLibrary.dll'
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
    at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)

    === Pre-bind state information ===
    LOG: User = CShah
    LOG: Where-ref bind. Location = C:\Users\CShah\Documents\Visual Studio 2010\Projects\SilverLight\SSQueueServiceLibrary\bin\Debug\SSQueueServiceLibrary.dll
    LOG: Appbase = file:///C:/Users/CShah/Documents/Visual Studio 2010/Projects/SilverLight/SSQueueServiceLibrary/bin/Debug
    LOG: Initial PrivatePath = NULL
    Calling assembly : (Unknown).
    ===
    LOG: This bind starts in LoadFrom load context.
    WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
    LOG: Using application configuration file: C:\Users\CShah\Documents\Visual Studio 2010\Projects\SilverLight\SSQueueServiceLibrary\bin\Debug\SSQueueServiceLibrary.dll.config
    LOG: Using host configuration file:
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Attempting download of new URL file:///C:/Users/CShah/Documents/Visual Studio 2010/Projects/SilverLight/SSQueueServiceLibrary/bin/Debug/SSQueueServiceLibrary.dll.
    ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated."I am getting an error Bad Image Format Exception when i change the Platform Target to x86 from Any CPU.
    It doesn't throw an exception when running on "Any CPU" as Platform Target.

    My OS is Win 7 x64. I figured out that as 64-bit framework being used, it is throwing the exception.
    "LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config."

    Now the problem is i am using Sybase database and i have a 32-bit dll and not x64.
    So if "Any CPU" is selected and i run the service, i am getting exception for memory location just while i create a connection object.
    AseConnection oAseCon = new AseConnection(str);

    Is there a solution that i can run a 3rd party 32-bit dll in a WCF Service on 64 bit machine.

    Help would be appreciated.

    Thanks .

    • Merged by Yi-Lun Luo Thursday, March 29, 2012 2:10 AM D
    Wednesday, March 28, 2012 1:16 PM
  • If you build your WCF service in x86 mode, then the host should also be built in x86 mode. Check whether your WCF Service host is built in Any CPU mode. If yes, build it in x86 mode instead.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by Yi-Lun Luo Tuesday, April 03, 2012 9:12 AM
    Wednesday, March 28, 2012 4:36 PM
  • The issue you get is because your application references some dlls that are build explicitly for 32bit OS. 

    In order to solve the above issue you need to do the following:

    1. Open your IIS

    2. Check under which app pool your application is running.

    3. Open the advance settings of that app pool.

    4. You have a setting "Enable 32-bit Application" which should be set to True.

    Doing the above should resolve your issue.


    Rajesh S V

    • Marked as answer by Yi-Lun Luo Tuesday, April 03, 2012 9:12 AM
    • Unmarked as answer by Yi-Lun Luo Tuesday, April 03, 2012 9:13 AM
    Thursday, March 29, 2012 9:45 AM
  • If you build your WCF service in x86 mode, then the host should also be built in x86 mode. Check whether your WCF Service host is built in Any CPU mode. If yes, build it in x86 mode instead.


    Please mark this post as answer if it solved your problem. Happy Programming!


    How do you change of the WCF Service Host is built?
    Wednesday, June 19, 2013 3:14 PM
  • I have the same problem - and since I am using a WCF project the startup when I hit F5 is with command line argument /client:"WcfTestClient.exe"

    I guess that WCFTestClient is written using Any CPU?

    I appreciate any help...

    /Tomas

    Tuesday, December 10, 2013 4:02 PM