2

I am using Visual Studio 2010 on a 64 bit Windows 7 machine.
In Visual Studio I am creating a .NET 4 Visual C# ASP.NET Empty Web Application.
I add a Default.aspx file to the project with the text "Hello World".
If I select Debug -> Start Debugging it opens a web browser and correctly displays the text.

However, if I go into Properties -> Build -> Platform Target and change it to x64. enter image description here

When I select Debug -> Start Debugging it opens a web browser with the following error message:

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

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

However, I can deploy it to a separate 64 bit windows 2008 r2 IIS server on an application pool with "Enable 32-Bit Applications" set to False and the application runs fine even if I add 64 bit .dlls to the project.

Is it not possible to debug 64 bit applications in Visual Studio using the built in Visual Studio Development Server?

In the toolbar next to the Debug dropdown I only have one option "Any CPU":

enter image description here

Any help on this would be greatly appreciated.

Baxter
  • 5,633
  • 24
  • 69
  • 105

1 Answers1

7

It has to do with debugging a 64 bit dll in a 32 bit application (the dev version of IIS used for debugging is 32 bit). You will have to do your debugging in 32 bit mode locally, and then target 64 bit upon deployment.

This question talks about a 64 bit replacement for the WebDev server used in Visual Studio 2010 Is Visual Studio 2010 WebDev WebServer (Cassini) 64-bit compatible?.

Microsoft's not so easy to use remote debugging for 64 bit web applications How to: Debug 64-Bit Applications.

Another thing you can try is installing IIS Express. It will run in 64 bit mode and can be used for debugging purposes. The linked article is actually for VS2013, but change the registry paths from 12.0 to 10.0 to make it work with VS2010.

For VS2013: Debugging VS2013 Websites Using 64-bit IIS Express

Command-Line:

reg add HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\WebProjects 
/v Use64BitIISExpress /t REG_DWORD /d 1

For VS2012: Allow for IIS Express 64 bit to run from Visual Studio 2012

You can configure Visual Studio 2012 to use IIS Express 64-bit by setting the following registry key:

reg add HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\WebProjects 
/v Use64BitIISExpress /t REG_DWORD /d 1
Community
  • 1
  • 1
Adam Zuckerman
  • 1,633
  • 1
  • 14
  • 20
  • So I would need to remove all of my 64 bit .dll dependencies and replace them with 32 bit versions for debugging then do the opposite when I need to publish to the 64bit webserver? Is this just for Visual Studio 2010, or is there a 64 bit debugging option in newer versions of Visual Studio? – Baxter Apr 27 '14 at 02:19
  • 1
    I made some significant updates to the answer that include links to several different methods on how to debug using 64 bit. – Adam Zuckerman Apr 27 '14 at 02:49
  • 2
    Oh cool thanks for the links. It also looks like you can set IIS Express to 64bit in Visual Studio 2013 from the application: There is an now option for this in Visual Studio 2013. Tools | Options | Projects and Solutions | Web Projects | Use the 64 bit version of IIS Express… – Baxter Apr 27 '14 at 02:56