【问题标题】:Error "The root element must match the name of the section referencing the file", when root element does match the name of the section错误“根元素必须与引用文件的部分的名称匹配”,当根元素与部分的名称匹配时
【发布时间】:2017-10-11 10:17:54
【问题描述】:

我正在尝试使用“文件”属性将 appSettings 配置部分移动到外部文件并不断收到错误:

System.Configuration.ConfigurationErrorsException : 根元素 必须与引用文件的部分的名称“appSettings”相匹配

问题是外部文件中的根元素已经是“appSettings”。 尝试使用根“配置”和自定义配置部分,但也没有帮助

外部文件Test.config在下面

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
  <add key="URL" value="https://www.google.com" />
</appSettings>

App.config文件

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
  </configSections>
  <specFlow>
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
  </specFlow>
  <appSettings file="Test.config"/>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>

谁能帮我解决这个问题?

谢谢。

【问题讨论】:

    标签: c# config


    【解决方案1】:

    对我来说,这是一个路径问题。 Visual Studio 的默认行为是不在输出目录中包含该文件。我将每个构建的文件属性更改为“始终复制”,以确保您拥有最新的文件。如果您已在属性部分将其添加到项目中,则文件引用应在路径中包含属性文件夹。

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 2021-11-15
      • 2017-10-23
      • 2015-03-22
      • 2011-07-04
      • 1970-01-01
      相关资源
      最近更新 更多