Visual Studio always selects the wrong xsd for App.config

我的未来我决定 提交于 2019-11-27 06:45:45

I interpret the problem as following: the file DotNetConfig.xsd has wrong (or not full) definition of the <startup> element. The 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 not as 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) to 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 cause one can define the schema of all attributes or elements more detailed (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 contain of the catalog.xml file from the same directory, which schema 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 interprets by Visual Studio as files with the XSD schema described by one from above files.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!