【问题标题】:How to resolve "Could not find schema information for the element/attribute <xxx>"?如何解决“找不到元素/属性 <xxx> 的架构信息”?
【发布时间】:2026-01-01 18:15:01
【问题描述】:

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

当我打开我的 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'.  

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

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

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

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

【问题讨论】:

  • 嘿,对不起,我帮不了你。如果您希望我删除我的答案以使您的问题显示为未回答,请对答案发表评论,以便我下次登录时可以看到。
  • 我通过重启我的视觉工作室解决了这个问题。

标签: .net xml xsd enterprise-library


【解决方案1】:

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

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

【讨论】:

  • 在 XSD 中,您可能需要添加 minOccurs="0" 以便在移动/删除部分时不会收到验证警告,例如
  • 只想添加这个“架构”属性,您只能通过编辑 xml 文件 (app.config) 而不能通过浏览解决方案资源管理器访问
  • 我按照您上面的描述创建了一个 xsd 架构。我确实帮助我摆脱了“找不到...的架构信息” - 消息,但是现在我收到警告“全局元素'配置'已经被声明。”在 app.xsd 中。有谁知道如何解决这个问题?
  • 在 Visual Studio 2010 中,要找到“创建架构”按钮,首先打开“app.config”以启用 XML 工具,然后将鼠标悬停在工具栏上的按钮上。如果仍然找不到,请右键单击工具栏,并确保选中“XML 编辑器”。您也可以使用菜单“XML..Create Schema”。
  • 这是否也适用于 ASP.NET MVC 项目的 web.config?我已将创建的 xsd 文件添加到我的 web.config 的架构中,但错误并没有消失。
【解决方案2】:

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

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

上下文

  • Visual Studio 2010
  • 企业库 5

删除警告的步骤

  1. 在您的 Visual Studio 项目中打开 app.config
  2. 在 XML 文档编辑器中单击鼠标右键,选择“属性”
  3. 将完全限定路径添加到“EnterpriseLibrary.Configuration.xsd”

一边

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

【讨论】:

  • 超级简单的解决方案。如果您在打开属性后单击路径变量右侧的省略号按钮,则更简单——这会弹出一个对话框,您可以在其中简单地单击要包含的 XML 模式...
【解决方案3】:

我使用 EntLib 配置工具配置了 app.config,并设置了我的 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>

【讨论】:

  • 这很好用!!!谢谢你的技术。现在我知道如何为远程配置制作一个了。
  • 我将第 3 行的顺序更改为全部,以便各部分可以按任意顺序显示。
  • @user57433 - EntLib 配置工具和 DotNetConfig.xsd 文件在哪里?
  • 工作量太大了。您可以只打开 app.config 的属性,单击 Path 变量,然后单击省略号按钮。这会弹出一个对话框,您可以在其中选择要包含的任何架构。
【解决方案4】:

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

更新:安装 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>

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

【讨论】:

    【解决方案5】:

    对我来说,解决“找不到元素的架构信息...”的问题是

    • 打开我的app.config
    • 在编辑器窗口中右击并选择Properties
    • 在属性框中,有一行名为Schemas,我点击了该行并选择了该行中出现的浏览...框。
    • 我只是检查了use 框,以查看包含我的项目的所有行,以及我正在使用的当前版本的.Net。例如:DotNetConfig30.xsd

    之后一切正常。

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

    【讨论】:

      【解决方案6】:

      导航至此:NLog xsd files

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

      第一个对我有用。

      【讨论】: