24

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?

Community
  • 1
  • 1
Sebastian P.R. Gingter
  • 5,955
  • 3
  • 31
  • 73

3 Answers3

45

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.

Palle Due
  • 5,929
  • 4
  • 17
  • 32
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • 1
    Thanks. That did the trick. I didn't even thought about the possibility that the xsd's shipping with VS could be wrong. – Sebastian P.R. Gingter Dec 09 '10 at 17:52
  • @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! – Oleg Dec 09 '10 at 18:15
  • Got rid of 41 warnings for me also. Thanks a lot :) – Øyvind Bråthen Jun 22 '11 at 12:34
  • @Ø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. – Oleg Jun 22 '11 at 15:36
  • Even in SP1 it does not seem to be fixed, sad. But thanks for the great answer. – lanoxx Jan 30 '12 at 10:59
  • @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 – cihadakt Feb 22 '13 at 11:45
  • @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. – Oleg Feb 22 '13 at 11:58
  • Saved me a lot of time with this.. And this annoying message is now gone finally! – David Eaton Jul 10 '13 at 14:36
  • @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. – Oleg Jul 10 '13 at 14:58
  • Mine won't allow me to save the file – user2602079 Dec 11 '13 at 02:15
  • @user2602079: You should have administrative rights if you want to modify files from Program Files. – Oleg Dec 11 '13 at 06:39
  • Note, `startup` was on line 212, not 230, for me, in VS 2005. – vapcguy Mar 15 '20 at 06:41
1

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.

gremlin
  • 73
  • 6
0

This is an old post - but I just encountered the same problem.

The approach I took was the same one Ken Johnsrude suggested above - to create a new .xsd file:

http://w3stack.org/question/c-how-to-fix-error-could-not-find-schema-information-for-the-attributeelement-by-creating-schema/

  1. MSVS > Open project app.config

  2. XML > Create Schema

    This will create "app.xsd" in %TEMP%

     EXAMPLE: c:\users\paulsm\AppData\Local\Temp\app.xsd
    
  3. Move app.xsd to project directory

  4. App.Config, Right-click > Properties > Schemas > ... app.xsd > Use > Use this schema = YES

paulsm4
  • 114,292
  • 17
  • 138
  • 190