2012-03-27 4 views
3

.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> 

、私はキーを追加しようとしたとき、私はプロンプトのために取得するすべての コメントしているか、私は

object obj = ConfigurationManager.GetSection("MonitorFldrSection"); 

は、私はこのエラーを取得するコードにアクセスしようとすると、CDATAが

を促し:{"MonitorFldrSectionの構成セクションハンドラを作成する際にエラーが発生しました:ファイルまたはアセンブリ 'System、Version = 4.0.0.0'またはその依存関係の1つを読み込めませんでした。システムが指定されたファイルを見つけることができません(C:\ Projects_4.0 \ NasImageIndexer \ TestForm \ bin \ Debug \ TestFor m.exe.Config line 5) "}

NameValueFileSectionHandlerと一緒にAppSettingsSectionとDictionarySectionHandlerも試しました。

私は間違っていますか?

答えて

0

このファイルは、C:¥Projects_4.0¥NasImageIndexer¥TestForm¥bin¥Debug¥TestForm.exe.Configの場所にありますか?

設定ファイル用の ビルドアクションプロパティを変更しない場合 - 出力ディレクトリにコンテンツ コピー - 常に

編集済みコピーを:

をこれは、公開キートークンを追加した後、私のために働いたと代わりに名前をキーに変更してください

<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> 
+0

はい、私はTestForm.exe.Configを見つけることができますが、getti同じエラー – edepperson

+0

愚かですが、リリースモードで実行している場合は、このエラーを何度か繰り返していましたが、デバッグモードでbin \ releaseを確認してください。bin \ debugを確認してください。 – Kiru

+0

何が、 Version = 4.0.0.0ですが、そのファイルはC:¥Program Files¥Reference Assemblies¥Microsoft¥Framework¥.NETFramework¥v4.0にあります。しかし、そのバージョンは4.0.30319.1です。 – edepperson

関連する問題