WcfSvcHost BadImageFormatException RRS feed

  • Question

  • Hi,

        I have a WCF project that was working fine on Windows 8 but since upgrading to 8.1 whenever I try to debug it the WcfSrvHost fails with a BadImageException. I've checked that all the projects have an x86 profile (there are some legacy dll's that are 32bit) but when I switch the wcf trace logging on I can see that it tries to use the 64bit version of the .Net 2 framework. See below (username and pcname have been edited for security):

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

    === Pre-bind state information ===
    LOG: User = *****pc\*****USER
    LOG: Where-ref bind. Location = C:\Users\*****USER\Documents\Visual Studio 2008\Projects\CellController\MCCwcfInterface\bin\x86\Debug\MCCwcfInterface.dll
    LOG: Appbase = file:///C:/Users/*****USER/Documents/Visual Studio 2008/Projects/CellController/MCCwcfInterface/bin/x86/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\*****USER\Documents\Visual Studio 2008\Projects\CellController\MCCwcfInterface\bin\x86\Debug\MCCwcfInterface.dll.config
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
    LOG: Attempting download of new URL file:///C:/Users/*****USER/Documents/Visual Studio 2008/Projects/CellController/MCCwcfInterface/bin/x86/Debug/MCCwcfInterface.dll.
    ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

    This solution used to compile and debug correctly before upgrading to Windows 8.1.

    I also tried creating a brand new solution with a WPF app and a WCF service. I didn't edit any code so it is just using the standard code produced by the project template. When I debug it with 'Any CPU' selected it works OK. When I use 'x86' I get the same error.

    Why is it trying to use .Net 2.0 when the project is a .Net 3.5 app?

    I submitted this question to the Windows 8.1 forum and was advised to submit it here so please don't pass me back to the 8.1 forum again.


    • Edited by SRichardson Monday, November 25, 2013 2:57 PM
    Monday, November 25, 2013 2:33 PM


  • Hi,

    When occur the problem, it may because that the WcfServiceHost in VS2008 is not able to accept 32 Bit DLLs. Please try to refer to the following solution about how to fix it:

    1. Copy WcfSvcHost.exe from C:\program files (x86)\Microsoft Visual Studio 9.0\Common7\IDE to a local directory. Keep a backup copy of this file, of course.
    2. Start a Visual Studio 2008 Command Prompt (one of the links from the start menu -> Visaul Studio 2008)
    3. “cd” to the directory where your copy of WcfSvcHost is located.
    4. Execute the command “corflags /32BIT+ /FORCE WcfSvcHost.exe”
    5. Copy the exe back to where you found it.

    Also please try to refer to this article:

    #BadImageFormatException encountered with WcfSvcHost and IIS WCF host: .

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 26, 2013 2:44 AM