Visual Studio 2010 publish / web.config conflict

Yesterday, I suddenly and mysteriously started getting this error message when trying to build my ASP.NET MVC 2 application.

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level

It’s mysterious because I didn’t change my .configs. Double-clicking on the error took me to the <authentication> section of the web.config at the root of my app. It’s legal to define it there. Strange.

After trying a few different things, I started commenting out larger and larger chunks of my config, until it looked like this:

<configuration><!-- ... --></configuration>

Clearly, the error message was wrong.

As it turns out, this was my first time to build the app after using VS 2010’s Publish feature to throw it up on a server for a demo & user testing. Publishing packages up the website under .objReleasePackage, and it doesn’t clean up after itself. The next time I built my application, the compiler barked because I had a web.config hidden a few layers deep under .obj with an <authentication> element.

I discovered the issue when I compiled my app at the command line and saw the full path on the error message. So, kill the .obj folder after each publish, and you’ll never have this trouble.

blog comments powered by Disqus