Web.config Error in Build after Publish

If you publish an ASP.Net (MVC) application in VS 2010, you need to define a Target Location in the Publish… dialog.

VS then builds and publishes. Another manual build will result in the error message

Error 3 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.

For better entertainment, the file name that causes the error is displayed as “web.config” in the Error List window.

Right-click and select Copy will fill the clipboard with the real file path, which is


which is a relict of the publishing process.

The solution is to delete everything from the obj\Debug and obj\Release directories (depending on your build configuration) and build again.


Executing “Clean Solution” or “Clean Project” also solves the problem.

One Response to Web.config Error in Build after Publish

  1. […] I encountered this error message before, and in that case you should be able to solve the problem by running Clean on the project or the […]

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: