.net 如何解决“找不到元素/属性 <xxx> 的架构信息”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/179927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 10:15:52  来源:igfitidea点击:

How to resolve "Could not find schema information for the element/attribute <xxx>"?

.netxmlxsdenterprise-library

提问by StingyHyman

In visual studio, I have an asp.net 3.5 project that is using MS Enterprise Library 4.0 application blocks.

在 Visual Studio 中,我有一个使用 MS Enterprise Library 4.0 应用程序块的 asp.net 3.5 项目。

When I have my web config file open, my Error list fills up with 99 messages with things like

当我打开 Web 配置文件时,我的错误列表会填满 99 条消息,例如

Could not find schema information for the element 'dataConfiguration'.  
Could not find schema information for the attribute 'defaultDatabase'.  
Could not find schema information for the element 'loggingConfiguration'.   
Could not find schema information for the attribute 'tracingEnabled'.   
Could not find schema information for the attribute 'defaultCategory'.  

If I close the Web.config file they go away (but they come back as soon as I need to open the file again).

如果我关闭 Web.config 文件,它们就会消失(但一旦我需要再次打开文件,它们就会回来)。

After doing some looking, I found that this is becauase there is an XSD or schema file missing that Visual Studio needs in order to properly 'understand' the schema that is in the web.config file and provide intellisense for it.

经过一番查找,我发现这是因为缺少 Visual Studio 需要的 XSD 或架构文件,以便正确“理解” web.config 文件中的架构并为其提供智能感知。

Does anyone know how to either supply VS with the appropriate schema information, or to turn off these messages?

有谁知道如何向 VS 提供适当的架构信息,或者关闭这些消息?

@Franci - Thanks for the info, I have tried that tool as well as the MMC snap in (they tend to blow up the formatting in the Web.config) but they still do not resolve the irritating warnings I receive. Thanks for trying.

@Franci - 感谢您提供的信息,我已经尝试过该工具以及 MMC 管理单元(它们往往会破坏 Web.config 中的格式),但它们仍然无法解决我收到的恼人警告。感谢您的尝试。

采纳答案by user57433

I configured the app.configwith the tool for EntLib configuration and set up my LoggingConfigurationblock. Then I copied this into the DotNetConfig.xsd. Of course, it does not cover all attributes, only the ones I added but it does not display those annoying info messages anymore.

app.config使用 EntLib 配置工具配置了 ,并设置了我的LoggingConfiguration块。然后我将其复制到DotNetConfig.xsd. 当然,它并没有涵盖所有属性,只有我添加的属性,但它不再显示那些烦人的信息消息。

<xs:element name="loggingConfiguration">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="listeners">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded" name="add">
              <xs:complexType>
                <xs:attribute name="fileName" type="xs:string" use="required" />
                <xs:attribute name="footer" type="xs:string" use="required" />
                <xs:attribute name="formatter" type="xs:string" use="required" />
                <xs:attribute name="header" type="xs:string" use="required" />
                <xs:attribute name="rollFileExistsBehavior" type="xs:string" use="required" />
                <xs:attribute name="rollInterval" type="xs:string" use="required" />
                <xs:attribute name="rollSizeKB" type="xs:unsignedByte" use="required" />
                <xs:attribute name="timeStampPattern" type="xs:string" use="required" />
                <xs:attribute name="listenerDataType" type="xs:string" use="required" />
                <xs:attribute name="traceOutputOptions" type="xs:string" use="required" />
                <xs:attribute name="filter" type="xs:string" use="required" />
                <xs:attribute name="type" type="xs:string" use="required" />
                <xs:attribute name="name" type="xs:string" use="required" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="formatters">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="add">
              <xs:complexType>
                <xs:attribute name="template" type="xs:string" use="required" />
                <xs:attribute name="type" type="xs:string" use="required" />
                <xs:attribute name="name" type="xs:string" use="required" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="logFilters">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="add">
              <xs:complexType>
                <xs:attribute name="enabled" type="xs:boolean" use="required" />
                <xs:attribute name="type" type="xs:string" use="required" />
                <xs:attribute name="name" type="xs:string" use="required" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="categorySources">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded" name="add">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="listeners">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="add">
                          <xs:complexType>
                            <xs:attribute name="name" type="xs:string" use="required" />
                          </xs:complexType>
                        </xs:element>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
                <xs:attribute name="switchValue" type="xs:string" use="required" />
                <xs:attribute name="name" type="xs:string" use="required" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="specialSources">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="allEvents">
              <xs:complexType>
                <xs:attribute name="switchValue" type="xs:string" use="required" />
                <xs:attribute name="name" type="xs:string" use="required" />
              </xs:complexType>
            </xs:element>
            <xs:element name="notProcessed">
              <xs:complexType>
                <xs:attribute name="switchValue" type="xs:string" use="required" />
                <xs:attribute name="name" type="xs:string" use="required" />
              </xs:complexType>
            </xs:element>
            <xs:element name="errors">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="listeners">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="add">
                          <xs:complexType>
                            <xs:attribute name="name" type="xs:string" use="required" />
                          </xs:complexType>
                        </xs:element>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
                <xs:attribute name="switchValue" type="xs:string" use="required" />
                <xs:attribute name="name" type="xs:string" use="required" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="tracingEnabled" type="xs:boolean" use="required" />
    <xs:attribute name="defaultCategory" type="xs:string" use="required" />
    <xs:attribute name="logWarningsWhenNoCategoriesMatch" type="xs:boolean" use="required" />
  </xs:complexType>
</xs:element>

回答by user57433

I've created a new scheme based on my current app.config to get the messages to disappear. I just used the button in Visual Studio that says "Create Schema" and an xsd schema was created for me.

我根据我当前的 app.config 创建了一个新方案,以使消息消失。我刚刚使用了 Visual Studio 中显示“创建架构”的按钮,并为我创建了一个 xsd 架构。

Save the schema in an apropriate place and see the "Properties" tab of the app.config file where there is a property named Schemas. If you click the change button there you can select to use both the original dotnetconfig schema and your own newly created one.

将架构保存在适当的位置,然后查看 app.config 文件的“属性”选项卡,其中有一个名为 Schemas 的属性。如果您单击那里的更改按钮,您可以选择使用原始 dotnetconfig 架构和您自己新创建的架构。

回答by Pressacco

An XSD is included with EntLib 5, and is installed in the Visual Studio schema directory. In my case, it could be found at:

XSD 包含在 EntLib 5 中,并安装在 Visual Studio 架构目录中。就我而言,它可以在以下位置找到:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas\EnterpriseLibrary.Configuration.xsd"

“C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas\EnterpriseLibrary.Configuration.xsd”

CONTEXT

语境

  • Visual Studio 2010
  • Enterprise Library 5
  • 视觉工作室 2010
  • 企业库 5

STEPS TO REMOVE THE WARNINGS

消除警告的步骤

  1. open app.config in your Visual Studio project
  2. right click in the XML Document editor, select "Properties"
  3. add the fully qualified path to the "EnterpriseLibrary.Configuration.xsd"
  1. 在 Visual Studio 项目中打开 app.config
  2. 右键单击 XML 文档编辑器,选择“属性”
  3. 将完全限定的路径添加到“EnterpriseLibrary.Configuration.xsd”

ASIDE

在旁边

It is worth repeating that these "Error List" "Messages" ("Could not find schema information for the element") are only visible when you open the app.config file. If you "Close All Documents" and compile... no messages will be reported.

值得重申的是,这些“错误列表”“消息”(“找不到元素的架构信息”)仅在您打开 app.config 文件时可见。如果您“关闭所有文档”并编译...不会报告任何消息。

回答by Franci Penov

Have you tried copying the schema file to the XML Schema Caching folder for VS? You can find the location of that folder by looking at VS Tools/Options/Test Editor/XML/Miscellaneous. Unfortunately, i don't know where's the schema file for the MS Enterprise Library 4.0.

您是否尝试将架构文件复制到 VS 的 XML 架构缓存文件夹?您可以通过查看 VS Tools/Options/Test Editor/XML/Miscellaneous 来找到该文件夹​​的位置。不幸的是,我不知道 MS Enterprise Library 4.0 的架构文件在哪里。

Update: After installing MS Enterprise Library, it seems there's no .xsd file. However, there's a tool for editing the configuration - EntLibConfig.exe, which you can use to edit the configuration files. Also, if you add the proper config sections to your config file, VS should be able to parse the config file properly. (EntLibConfig will add these for you, or you can add them yourself). Here's an example for the loggingConfiguration section:

更新:安装 MS Enterprise Library 后,似乎没有 .xsd 文件。但是,有一个用于编辑配置的工具 - EntLibConfig.exe,您可以使用它来编辑配置文件。此外,如果您将适当的配置部分添加到配置文件中,VS 应该能够正确解析配置文件。(EntLibConfig 会为您添加这些,或者您可以自己添加它们)。这是 loggingConfiguration 部分的示例:

<configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>

You also need to add a reference to the appropriate assembly in your project.

您还需要在项目中添加对适当程序集的引用。

回答by Wade Price

What fixed the "Could not find schema information for the element ..." for me was

对我来说修复“找不到元素的架构信息......”的是

  • Opening my app.config.
  • Right-clicking in the editor window and selecting Properties.
  • In the properties box, there is a row called Schemas, I clicked that row and selected the browse ...box that appears in the row.
  • I simply checked the usebox for all the rows that had my project somewhere in them, and also for the current version of .Net I was using. For instance: DotNetConfig30.xsd.
  • 打开我的app.config.
  • 在编辑器窗口中右键单击并选择Properties.
  • 在属性框中,有一行名为Schemas,我单击了该行并选择了该行...中出现的浏览框。
  • 我只是选中了use包含我的项目的所有行的框,以及我正在使用的当前版本的 .Net。例如:DotNetConfig30.xsd

After that everything went to working fine.

之后一切正常。

How those schema rows with my project got unchecked I'm not sure, but when I made sure they were checked, I was back in business.

我不确定我的项目中的那些模式行是如何被取消选中的,但是当我确定它们被选中时,我又重新开始工作了。

回答by darkmatter

Navigate to this : NLog xsd files

导航到这个:NLog xsd 文件

Download the appropriate xsd for your project and save it along the NLog.config

为您的项目下载适当的 xsd 并将其保存在 NLog.config 中

The first one did the trick for me.

第一个为我做了伎俩。