If you have a 32bit ASP.NET application and decided to port to Windows Azure application you will do the following:
- 1. Create a Web Role using Windows Azure SDK 1.3
- 2. Add existing Website (hosted on a 32-bits server) converted to Web Application.
- 3. Build
- 4. Test locally in Compute Emulator
- 5. Deploy it
Now it is possible that when your website runs in cloud you might get the following error:
Server Error in '/' Application.
is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
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: is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
Version Information: Microsoft .NET Framework Version:2.0.50727.4206; ASP.NET Version:2.0.50727.4209
The reason for this problem is that the IIS server doesn't have 32bit application support enabled in Application Pool so to fix this error you will need to enable 32 bit applications in the Application pool. And to make it happen, you will need to create a "Startup Task" to enabled 32-Bit application support in IIS and this has to be done in your Windows Azure Application. Here are the detailed steps:
1. Create a BATCH file with proper command lines which can run the script to enable 32Bit application support in IIS as below:
%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.enable32BitAppOnWin64:true
2. Add this BATCH file into Windows Azure Application Startup Task by adding the following lines in ServiceDefinition.csdef to enable 32-bit application in IIS advance setting
<Task commandLine="Enable32BitAppPool.cmd" executionContext="elevated" taskType="simple">
3. Please set the file Enable32BitAppPool.cmd property to "Copy Local" as true so this batch file will be deployed to Azure Portal with your package.