Visual Studio confused when there are multiple system.web sections in your web.config
I am trying to start debugging in Visual Studio for the website I am currently working on but Visual Studio is telling me that I have to enable debugging in the web.config to continue:
But I clearly have debugging enabled:
At first I chose the option to Modify the Web.config file to enable debugging but then I started receiving the following exception on my site:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Config section 'system.web/compilation' already defined. Sections must only appear once per config file. See the help topic <location> for exceptions
So what is going on here? I already have debug=”true”, Visual Studio tells me I do not, and then when I give Visual Studio permission to fix the problem, I get a configuration error.
Eventually I tracked it down to having two <system.web> sections.
I had defined customErrors higher in the web.config:
And then had a second system.web section with compilation debug=”true” further down in the web.config. This is valid in the web.config and my site was not complaining but I guess Visual Studio does not know how to handle it and sees the first system.web, does not see the debug=”true” and thinks your site is not set up for debugging.
To fix this so that Visual Studio was not going to complain, I removed the duplicate system.web declaration and moved the customErrors statement down.