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 .\obj\Release\Package, 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.




#1 by Simon Lomax on July 20th, 2010
Jason, I was getting exactly the same issue last week. I posted this question on StackOverflow but got no replies.
http://stackoverflow.com/questions/3204747/problem-after-publishing-web-application-from-vs-2010
Its a real pain to have to remember to delete the obj folder all the time, which is what I’ve been doing too. Be great if someone knows a fix for this.
#2 by Jason on July 20th, 2010
Yep. It’s especially annoying because a person can google around for hours and find nothing but advice about IIS settings.
#3 by Steve Evans on July 21st, 2010
I came across the same issue, but I figured it out by clicking into the error and looking at the file it had opened up. The give away was the fact that by default it’s “Web.config” and when I double clicked the error it opened “web.config” The casing of the “w” seemed odd, but thanks to Visual Studio showing you the full path of the file when you over over the document’s tab it helped figure out what was going on. In my case I modified the BeforeBuild target of the project file to include the following:
#4 by Steve Evans on July 21st, 2010
Bah…forget to escape the tags:
<ItemGroup>
<BadPackageFiles Include=”$(MSBuildProjectDirectory)\obj\**\Package\PackageTmp\*.*” />
</ItemGroup>
<Message Text=”Removing the invalid Package files” />
<Delete Files=”@(BadPackageFiles)” />
#5 by Simon Lomax on July 22nd, 2010
@Steve, thanks, that solved the problem.