Visual Studio always selects the wrong xsd for App.config

17,358

Solution 1

I interpret the problem as follows: the file DotNetConfig.xsd has wrong (or not full) definition of the <startup> element. Line 230 of all DotNetConfig.xsd, DotNetConfig35.xsd, DotNetConfig30.xsd and DotNetConfig20.xsd files contains

<xs:element name="startup" vs:help="configuration/startup" />

On the other side Microsoft describes the startup settings schema as a non-empty element. So I suggest to replace the above line in DotNetConfig.xsd and in all DotNetConfigXX.xsd files from the %ProgramFiles%\Microsoft Visual Studio 10.0\Xml\Schemas directory (or %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Xml\Schemas directory on 64-bit systems) with the following lines:

<xs:element name="startup" vs:help="configuration/startup">
    <xs:complexType>
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="requiredRuntime" vs:help="configuration/startup/requiredRuntime">
                <xs:complexType>
                    <xs:attribute name="version" type="xs:string" use="optional" />
                    <xs:attribute name="safemode" type="xs:boolean" use="optional" />
                </xs:complexType>
            </xs:element>
            <xs:element name="supportedRuntime" minOccurs="1" maxOccurs="unbounded" vs:help="configuration/startup/supportedRuntime">
                <xs:complexType>
                    <xs:attribute name="version" type="xs:string" use="optional" />
                    <xs:attribute name="sku" type="xs:string" use="optional" />
                </xs:complexType>
            </xs:element>
        </xs:choice>
        <xs:attribute name="useLegacyV2RuntimeActivationPolicy" type="xs:boolean" use="optional" />
        <!-- see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx -->
    </xs:complexType>
</xs:element>

After such modification and restarting of Visual Studio 2010 you will not have the warnings which you described. Of course one can define the schema of all attributes or elements in a more detailed manner (especially if we find more detailed documentation of the <startup> section), but I want to describe the reason of the problem only and one way to fix it.

By the way the choice between DotNetConfig.xsd, DotNetConfig35.xsd and other DotNetConfigXX.xsd files will be done based on the contents of the catalog.xml file from the same directory, the schema of which is described here. The standard version of the catalog.xml file contains the following lines:

<Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig20.xsd" condition="starts-with($TargetFrameworkMoniker, '.NETFramework,Version=v2.')" />
<Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig30.xsd" condition="starts-with($TargetFrameworkMoniker, '.NETFramework,Version=v3.0')" />
<Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig35.xsd" condition="starts-with($TargetFrameworkMoniker, '.NETFramework,Version=v3.5')" />
<Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig.xsd"   condition="starts-with($TargetFrameworkMoniker, '.NETFramework,Version=v4.') or $TargetFrameworkMoniker = ''" />

So all files having .config extension will be interpreted by Visual Studio as files with the XSD schema described by one from above files.

Solution 2

When I ran into this problem, the reason un-checking the schema didn't take turned out to be having multiple instances of Visual Studio open.

(I had VS2015 open with one project and VS2013 also open at the same time with a different project.)

Note, multiple versions of Visual Studio and switching back and forth on the same project/solution also seems to be how some issues with repeated schemas occurred in the first place.

Share:
17,358

Related videos on Youtube

Sebastian P.R. Gingter
Author by

Sebastian P.R. Gingter

Consultant at Thinktecture AG, Fulltime geek, loving father and trying to become an even better .NET Ninja.

Updated on May 11, 2022

Comments

  • Sebastian P.R. Gingter
    Sebastian P.R. Gingter almost 2 years

    first of all, I have a .NET 4.0 application with this configuration:

    <?xml version="1.0"?>
    <configuration>
        <startup>
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
        </startup>
    </configuration>
    

    I had the same problem like the one in this question: app.config "Could not find schema information" after converting to Visual Studio 2010 / .Net 4.0 : The supportedRuntime element was not recognized by the editor, resulting in a hint.

    I then followed the answer: I was in the app.config editor and went to the Properties window. There I selected the Schemas entry.

    I removed the selection of the DotNetConfig.xsd and selected the DotNetConfig35.xsd instead, but VS always automatically adds the DotNetConfig.xsd again. Even if I set it explicitely to "do not use this schema" or even remove the schema from the list - it is automatically added to the list again and selected.

    Because I now have two schemas selected that define the same elements I get a lot of warnings.

    How can I change the schema to use the DotNetConfig35.xsd and NOT have the DotNetConfig.xsd automatically added again?

  • Sebastian P.R. Gingter
    Sebastian P.R. Gingter over 13 years
    Thanks. That did the trick. I didn't even thought about the possibility that the xsd's shipping with VS could be wrong.
  • Oleg
    Oleg over 13 years
    @Sebastian P.R. Gingter: You welcome! Nobody is perfect. Microsoft too. It's not a good idea to have one XSD for all .config files (app.config, web.config and so on). So there are other close problems with config schema. Nevertheless I am glad to hear that I helped you. Mach's gut!
  • Øyvind Bråthen
    Øyvind Bråthen almost 13 years
    Got rid of 41 warnings for me also. Thanks a lot :)
  • Oleg
    Oleg almost 13 years
    @Øyvind Knobloch-Bråthen: You are welcome! I send also a lot of my time till I fond out the reason and solved it for me. Later I wrote the answer. I am sure that many people who look on the warnings of the Visual Studio spend his time for the strange messages. It's a pity that Micosoft till not not fixed the problem.
  • lanoxx
    lanoxx over 12 years
    Even in SP1 it does not seem to be fixed, sad. But thanks for the great answer.
  • cihadakt
    cihadakt about 11 years
    @Oleg I've changed as you described but I realized that RazorCustomSchema.xsd came selected default and cannot be removed. I want to select DotNetConfig40.xsd but can't select. Any suggestions? I am using VS 2012
  • Oleg
    Oleg about 11 years
    @cihata87: I suppose one should make modification of dotNetConfig40.xsd" in the close way like I suggested here. If you will not able to do this yourself you can open new question with description of the problem and with detailed description how it can be reproduced.
  • David Eaton
    David Eaton almost 11 years
    Saved me a lot of time with this.. And this annoying message is now gone finally!
  • Oleg
    Oleg almost 11 years
    @DavidEaton: I'm glad that my old answer could help you too. I'm wonder why Microsoft till now don't solved the problem in Visual Studio.
  • user2602079
    user2602079 over 10 years
    Mine won't allow me to save the file
  • Oleg
    Oleg over 10 years
    @user2602079: You should have administrative rights if you want to modify files from Program Files.
  • vapcguy
    vapcguy about 4 years
    Note, startup was on line 212, not 230, for me, in VS 2005.