C# 4.0 如何在.net 4.0中设置configSection

C# 4.0 如何在.net 4.0中设置configSection,c#-4.0,app-config,C# 4.0,App Config,我正在尝试为.net 4.0项目设置configSection <configuration> <configSections> <section name="MonitorFldrSection" type="System.Configuration.NameValueFileSectionHandler, System, Version=4.0.0.0" allowLocation="true"

我正在尝试为.net 4.0项目设置configSection

<configuration>
  <configSections>
    <section name="MonitorFldrSection"
         type="System.Configuration.NameValueFileSectionHandler, System, Version=4.0.0.0"
          allowLocation="true"
          allowDefinition="Everywhere"/>
  </configSections>
  <MonitorFldrSection>
    <add name="fldr1" value="C:\Temp" />
    <add name="fldr2" value="C:\Projects" />
  </MonitorFldrSection>
  <connectionStrings>
  </connectionStrings>
  <appSettings>
  </appSettings>
</configuration>
我收到以下错误:{“创建MonitorFldrSection的配置节处理程序时出错:无法加载文件或程序集“System,Version=4.0.0”或其依赖项之一。系统找不到指定的文件。(C:\Projects\u 4.0\naImageIndexer\TestForm\bin\Debug\TestForm.exe.Config第5行)}

除了NameValueFileSectionHandler,我还尝试了AppSettingsSection和DictionarySectionHandler


我做错了什么?

您能在位置C:\Projects\u 4.0\NasImageIndexer\TestForm\bin\Debug\TestForm.exe.Config中找到此文件吗

如果没有,请更改配置文件的属性 构建操作-内容 复制到输出目录-始终复制

编辑:

在添加公钥令牌并将名称改为key之后,这对我很有效

<configuration>
  <configSections>
   <section name="MonitorFldrSection"
type="System.Configuration.NameValueFileSectionHandler, System,   Version=4.0.0.0,         Culture=neutral, PublicKeyToken=b77a5c561934e089"
      allowLocation="true"
      allowDefinition="Everywhere"/>
</configSections>
<MonitorFldrSection>
<add key="fldr1" value="C:\Temp" />
<add key="fldr2" value="C:\Projects" />
</MonitorFldrSection>
<connectionStrings>
</connectionStrings>
<appSettings>
</appSettings>
</configuration>


是的,我可以找到TestForm.exe.Config,但仍然会遇到相同的错误这很愚蠢,但我已经犯了好几次这个错误,如果你在发布模式下运行,请检查你的bin\release如果它在调试模式下,请检查bin\debugh据说它无法加载我的系统,版本=4.0.0.0,但该文件位于C:\Program Files\Reference Assembly\Microsoft\Framework\.NETFramework\v4.0中。但是它的版本是4.0.30319.1。我在调试中,配置在调试文件夹中
<configuration>
  <configSections>
   <section name="MonitorFldrSection"
type="System.Configuration.NameValueFileSectionHandler, System,   Version=4.0.0.0,         Culture=neutral, PublicKeyToken=b77a5c561934e089"
      allowLocation="true"
      allowDefinition="Everywhere"/>
</configSections>
<MonitorFldrSection>
<add key="fldr1" value="C:\Temp" />
<add key="fldr2" value="C:\Projects" />
</MonitorFldrSection>
<connectionStrings>
</connectionStrings>
<appSettings>
</appSettings>
</configuration>