locked
Conversion to 64 bit application from (32 bit / Any CPU) causing application to throw error. RRS feed

  • Question

  • User-8554525 posted

    I am using VS Enterprise update 3  - 64 bit version on Windows server 2008. The Issue I am facing is that when a web application created in platform 32 bit changed to 64 bit, the applications fails runnung.  By following these steps with no code added causes the following error. 

    • Fire up VS 2015 Enterprise
    • create a new web application with 4.6.1 framework with name as DefautTest, select Web API option in the next window
    • Once the project is created, right click the project and navigate to Project properties and goto Build tab.
    • In the Build tab, change the Platform target from Any CPU to x64
    • run the application to get this error. 

    Server Error in '/' Application.


    Could not load file or assembly 'DefaultTest' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.BadImageFormatException: Could not load file or assembly 'DefaultTest' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Could not load file or assembly 'DefaultTest' or one of its dependencies. An attempt was made to load a program with an incorrect format

    Wednesday, May 24, 2017 11:59 AM

Answers

  • User1967761114 posted

    Hi bbalavikram,

    In your case ,your site is run with IIS Express, you could modify the option by the following steps:

    (1) In visual studio ,open menu "Tool" > "Options" .

    (2) Choose "Projects and Solutions" > "Web  Projects".

    (3) Checked the option of "Use the 64 bit version of IIS Express for web sites and projects".

    If you site had been deployed on IIS , you could refer to the following link.

    (1) You could find which application pool your web application using ,right click on your web application ,choose "Manage Web Site" > "Advanced Settings…" on the menu, then could find the application pool which your web application using in the dialog.

    (2) Find the application pool in application pools ,then click "Advanced Settings…".

       

    (3) Set the option "Enable 32-bit Applications" to false.

         

     

    If you have any other questions, please feel free to contact me any time.

    Best Regards

    Even

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 30, 2017 2:06 AM

All replies

  • User-2057865890 posted

    Hi bbalavikram,

    Exception Details: System.BadImageFormatException: Could not load file or assembly 'DefaultTest' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    The error is basically referring to a x86/x64 process/assembly mismatch. You're having a 32-bit / 64-bit conflict. It sounds like your main project might be set to 32-bit while the class its referencing is set to 64-bit. Change the value for Platform Target on your web project's property page to Any CPU.

    Best Regards,

    Chris

    Thursday, May 25, 2017 2:27 AM
  • User-8554525 posted

    Platform Target on your web project's property page to Any CPU

    I do not want to change to ANY CPU. I want the DLL to be 64 bit so that the DLL can handle more data and obtain more processing power. Also there is only one project in the solution and Platform Target of the project is set to x64...

    Thursday, May 25, 2017 12:26 PM
  • User1967761114 posted

    Hi bbalavikram,

    In your case ,your site is run with IIS Express, you could modify the option by the following steps:

    (1) In visual studio ,open menu "Tool" > "Options" .

    (2) Choose "Projects and Solutions" > "Web  Projects".

    (3) Checked the option of "Use the 64 bit version of IIS Express for web sites and projects".

    If you site had been deployed on IIS , you could refer to the following link.

    (1) You could find which application pool your web application using ,right click on your web application ,choose "Manage Web Site" > "Advanced Settings…" on the menu, then could find the application pool which your web application using in the dialog.

    (2) Find the application pool in application pools ,then click "Advanced Settings…".

       

    (3) Set the option "Enable 32-bit Applications" to false.

         

     

    If you have any other questions, please feel free to contact me any time.

    Best Regards

    Even

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 30, 2017 2:06 AM
  • User-8554525 posted

    (1) In visual studio ,open menu "Tool" > "Options" .

    (2) Choose "Projects and Solutions" > "Web  Projects".

    (3) Checked the option of "Use the 64 bit version of IIS Express for web sites and projects".

    For Any one facing this issue, this is the only way I also figured to make it work.. Please post any other possible solutions if you could create....

    Monday, June 12, 2017 11:12 AM