Eamon Nerbonne
Eamon Nerbonne

Reputation: 48066

Visual Studio 2012 XML intellisense broken due to auto-loading duplicate xsd files

In short: Can I prevent visual studio from loading some xsd's in it's internal intellisense engine? Loading certain xsd's breaks intellisense.


To perform input validation on various xml documents, I use xsd. Some of the xsd files I use are standard, such as xml.xsd and various xhtml xsd's. These xsd files are included in a class library as embedded resources.

However, having these files in the solution breaks the visual studio intellisense for all kinds of xml files, even in different projects. What seems to be happening is that both visual studio's own xsd files and the "custom" embedded xsd files are loaded, probably since they apply to the same targetNamespace. However, this causes lots of warnings such as: The global attribute 'http://www.w3.org/XML/1998/namespace:lang' has already been declared. It's particularly annoying for xslt files, but it seems to happen for all xml files that match multiple schemas. XHTML is another particularly problematic case since there are multiple schemas for just one namespace (strict, transitional...). As a consequence, intellisense stops working for the open xml file(s). Also, VS's error list is spammed with lots of spurious warnings, hiding potentially useful warnings from sight.

I can disable or remove these schemas using XML > Schemas... but this is an unworkable solution since they're all re-added whenever I open a different xml file. I'd have to remove the schemas possibly hundreds of times a day.

Is there any way to configure visual studio not to auto-load embedded schemas, or to load only specific schemas once and for all?

Upvotes: 2

Views: 1087

Answers (1)

Eamon Nerbonne
Eamon Nerbonne

Reputation: 48066

Based on the lack of response, I'm guessing this is simply a bug: intellisense simply can't deal with this situation.

I've submitted a bug report and will update this answer if a solution is found: http://connect.microsoft.com/VisualStudio/feedback/details/777572/visual-studio-2012-xml-intellisense-broken-due-to-auto-loading-duplicate-xsd-files

Solution/workaround

If you're locally including standard xsd's (which is almost certain given that they're conflicting with visual studio's own xsd's), you probably don't need to edit them much - just to include them as resources. I decided therefore to rename offending files such as xml.xsd to xml.xsd.intellisensehack. The file extension is irrelevant to the resource code (you can still open it like any other stream), but visual studio no longer automatically tries to use the file as an intellisense schema source.

Upvotes: 2

Related Questions