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.

1 thought on “Web.config Error in Build after Publish

  1. Pingback: Handling Web.Config Variants in Source Control-based Solutions | devioblog

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.