Domanda

Everything was working perfectly until VS2013 randomly started to complain about the tags in my web.config. It randomly tells literally nonsense errors such as duplicate declarations, random, non-existent tags at random whitespace. Here are a few screenshots demonstrating the issue:

enter image description here

enter image description here

I've tried resetting all Visual Studio settings, nothing changed. I've tried closing and re-opening all Visual Studi instances (obviously). I've tried copying the text, normalizing line endings in Sublime Text for Windows line endings, deleted config file, and saved the normalized text from Sublime Text, nothing changed. I have no idea what is happening. All other projects' web.config files are just working/parsing correctly. I've checked for any whitespace control characters, and there are no hidden whitespace characters in the file. What could possibly make VS go nuts about a particular web.config file, and work perfectly (including Intellisense completion) with all the others?

È stato utile?

Soluzione

Okay, it was definitely an internal error with Visual Studio, and from what I see (tags from other classes like XAML, which my project has nothing to do with etc) it's a serious one. Something in internal cache got corrupted somehow.

I've solved the problem by:

  • Cleaning solution (didn't change anything, but it was my first step)
  • Copying the text somewhere else
  • Deleting the web.config file completely.
  • Closing, reopening VS
  • Re-creating an empty web.config
  • Pasting the text back to the new file.

Even though it seems trivial, I think Visual Studio wasn't parsing the file again even when I changed the content. Deleting the file completely and closing VS probably erased everything related to the file from the internal cache, and when I pasted my perfectly correct XML into the new file, it forced to reparse, solving the problem.

Altri suggerimenti

While the problem is fixed by deleting the web.config file, closing, reopening and restoring the files helped, I still like to know what caused the problem. Tony Rush's answer helped me identify what the underlying problem was.

In my case i could see schema references with duplicate schemas for DotNetConfig.xsd, EntityFrameworkConfig_6_1_0.xsd and RazorCustomSchema.xsd referencing schema files in both visual studio 12.0 and 14.0 directories. Manually removing references to v12.0 files did not seem to do the trick, delete and restore file did.

The project with the problematic web.config has had Framework version changed from 4.5 to 4.5.2 and at the same time we changed from VS2013 to VS2015. Which of the two changes caused the problem i do not know.

Also, the schema references seem to be stored in a local settings file, as the fix does not cause any changes to check in to TFS.

For me, this was related to the XML Schemas being used by the web.config.

For example, it can occur if your project was created targeting .NET Framework 4.5 but then you changed the Target Framework to 4.0. Changing the Target Framework of your project does not update the XML Schemas used by your web.config. To fix this, open the web.config and then right-click it and choose 'Properties'. You will see under the XML Document properties you can modify the Schemas. In this example scenario, find 'DotNetConfig45.xsd' and choose 'Do not use this schema'.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top