none
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

    Question

  • Hi,

    I have a question for WPF : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B).

    I am using Windows 7 with 64 bits computer and Visual Studio 2008. I created a class library that uses a 3rd-party .dll file. I created two applications using Visual Studio 2008: one is web site, and the other is WPF. When I created these two applications, I just used the default setting by Visual Studio 2008. I run these applications using ANY CPU.

    These two applications both use the class library mentioned above. Now, the result is very strange:

    For the website, it worked very well. But for the WPF application, I got the error: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B).

     

    Any ideas about it? How to make it work on both applications?

     

    Thanks a lot.

     

     

    Tuesday, March 29, 2011 4:45 PM

Answers

  • so that the 3rd-party assembly supports x86 in you r Web Site, and please change you WPF application to x86 build mode. Then I think it can work with your WPF application  (do not use the ANY CPU)

    Sincerely,


    Bob Bao [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.

    • Marked as answer by FugersonHall Wednesday, March 30, 2011 6:33 PM
    Wednesday, March 30, 2011 4:12 AM
    Moderator

All replies

  • Hi FugersonHall,

    Please change your project Platform Setting to x86 or x64. I am not sure which platform the 3rd-party dll supports for. But ANY CPU may occur this error "0x8007000B" -- you may call the 32-bit dll in a 64-bit application in a 64-bit .Net enviroment.

    Sincerely,


    Bob Bao [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.

    Wednesday, March 30, 2011 3:59 AM
    Moderator
  • Hi Bob,

    Thanks a lot for your reply. In fact, this 3rd-party .dll has two version, x86 version and x64 version. If I use x86 version, the Web Site works, but the WPF application does not work. If I use x64 version, the Web Site does not work, but the WPF application works. But I need to make both of them work.

    Any ideas? 

    Wednesday, March 30, 2011 4:07 AM
  • so that the 3rd-party assembly supports x86 in you r Web Site, and please change you WPF application to x86 build mode. Then I think it can work with your WPF application  (do not use the ANY CPU)

    Sincerely,


    Bob Bao [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.

    • Marked as answer by FugersonHall Wednesday, March 30, 2011 6:33 PM
    Wednesday, March 30, 2011 4:12 AM
    Moderator
  • I have to use ANY CPU for both WPF and Web Site applications. 
    Wednesday, March 30, 2011 4:48 AM
  • Hi,

    Well, since your system is a 64-bit, WPF application in ANY CPU can use your 64-bit 3rd-party assembly. (ANY CPU in 64-bit is run as x64)

    But, you would like to run your web site in ANY CPU (means run your web site in x64 mode), it is determined by your server configuration after deployment (IIS configuration). Please try to set your IIS config:

    cscript %systemdrive%\inetpub\adminscripts\adsutil.vbs set w3svc/appPools/enable32bitapponwin64 0

    and C:\WINDOWS\Microsoft.NET\Framework64\[version]\aspnet_regiis - i

    to register the 64-bit ASP.Net  into your IIS. For more about IIS or ASP.Net question, you could try to consult at:

    I am not sure what is the type of your 3rd-party dll. Is it an unmanaged/managed dll? How do you import it into your projects?

    Sincerely,


    Bob Bao [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.

    • Proposed as answer by Tellarin Thursday, March 14, 2013 8:23 AM
    Wednesday, March 30, 2011 5:42 AM
    Moderator
  • Thanks for your so detailed explanation for this question. I changed the WPF application to X86 build, finally.
    Wednesday, March 30, 2011 6:34 PM