Website Exploded After Using VS2012

VS2008 + VS2012

Two years ago, my friend recommended me to try out the latest Visual Studio after he found out that I was still using VS2008. Recently, I finally decided to switch to use VS2012 while the latest version is already VS2013. Oh well, never mind. However, there was a strange error when I first published my ASP.NET website from VS2012 to the server. Part of the error message is shown below.

Server Error in '/' Application.
Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'.
 The request failed with the error message:
 <title>Configuration Error</title>
 body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
 p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
 b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
 H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
 H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
 pre {font-family:"Lucida Console";font-size: .9em}
 .marker {font-weight: bold; color: black;text-decoration: none;}
 .version {color: gray;}
 .error {margin-bottom: 10px;}
 .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>Configuration Error</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
<b> Parser Error Message: </b>It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.<br><br>

It turns out that I already did something wrong in the beginning of migration from older version of Visual Studio to VS2012. Normally, for projects created in older version of Visual Studio, they will need to go through some modifications before they can be opened in VS2012. So, there is a one-way upgrade performed when the project is opened in VS2012 for the first time.

There is a need to upgrade the project when it's created in older VS but is now opened in new VS.

There is a need to upgrade the project when it’s created in older VS but is now opened in new VS.

After the upgrade is done, a migration report will be available. In addition, there will be a Backup folder created in the solution directory. Visual Studio is so nice that it automatically creates a Backup folder storing the copy of the project before the one-way upgrade. However, this also creates a problem because inside the folder, there is a web.config file. So now there will be two web.config files in the solution directory. The error suggests that the code was expecting a virtual directory with only one web.config to be setup on IIS. Thus, having two web.config files in the same directory will cause the error mentioned above to happen.

So, the solution? Just move the Backup folder to somewhere else.

Sometimes, this solution may not be working for your case if you happen to encounter the same error. Hence, I’d like to share with you some other solutions which may help you.

Solution #2: Modify .csproj/.vsproj File

This solution is provided by Microsoft team on Visual Studio feedback page. They claimed that it’s a bug and it would be fixed in the future release of “ASP.NET Web Framework and Tools”.

Solution #3: Create Application on IIS

It turns out that if IIS application is not created, the same error will occur. We need to click on the “Create” button if we notice the “Application Name” is greyed out.

Solution #4: Clean the Project

There is a need to clean the solution before the build. There is a simple 3 steps to follow to do this, as suggested by Johnny Reilly on Stack Overflow.

  1. Clean solution when the solution is configured in Release mode;
  2. Clean solution whilst the solution is configured in Debug mode;
  3. Build the solution in Debug mode.

These are what I have found online so far. If you happen to find a solution that works for this issue, please post it as a comment here. Thank you!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s