我正在嘗試爲.net 4.0項目設置configSection。如何在.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>
然而,當我嘗試添加一個關鍵,我得到的提示是 評論或CDATA提示
當我嘗試訪問代碼
object obj = ConfigurationManager.GetSection("MonitorFldrSection");
我得到這個錯誤:{「爲MonitorFldrSection創建配置節處理程序時發生錯誤:無法加載文件或程序集'System,Version = 4.0.0.0'或其某個依賴項。系統找不到指定的文件(C:\ Projects_4.0 \ NasImageIndexer \ TESTFORM \ BIN \調試\ TestFor m.exe.Config line 5)「}
隨着NameValueFileSectionHandler,我也試過AppSettingsSection和DictionarySectionHandler。
我在做什麼錯?
是的,我可以找到TestForm.exe.Config,但仍然getti ng相同的錯誤 – edepperson 2012-03-27 14:40:07
這是愚蠢的,但我已經多次犯了這個錯誤,如果你在release模式下運行,檢查你的bin \ release,如果它處於調試模式check bin \ debug – Kiru 2012-03-27 14:45:02
說的是,它無法加載我的系統,版本= 4.0.0.0,但該文件位於C:\ Program Files \ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.0中。但其版本是4.0.30319.1。 – edepperson 2012-03-27 14:45:29