- - PR -
構成ファイルのSectionGroupのSingleTagSectionHandler項目 が取得できない
1
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2005-11-14 18:17
お世話になっております。
アプリケーション構成ファイルで独自のSectionGroupとSystem.Configuration.SingleTagSectionHandlerを追加していますが 取得時にエラーになります。 (エラー内容) System.Configuration.ConfigurationException' のハンドルされていない例外が system.dll で発生しました。 追加情報 : Unrecognized element ・・・こちらの情報はどうしてもセクショングループ化して、SingleTagSectionHandler のカスタム要素として取得したいのですが下記のようにしても取得できません。 セクショングループ化して、SingleTagSectionHandler のカスタム要素を取得する方法をご存知の方がいらしたら教えてください。 よろしくお願いいたします。 //app.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="myGroup"> <section name="mySettings1" type="System.Configuration.SingleTagSectionHandler,System,version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" /> <section name="mySettings2" type="System.Configuration.SingleTagSectionHandler,System,version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" /> </sectionGroup> <myGroup> </configSections> <mySettings1 key1="MyApp"/> <mySettings2 key1="value 1"key2="value 2" /> </myGroup> </configuration> //コード using System; using System.Configuration; using System.Collections; using System.Collections.Specialized; using System.Text; using System.Diagnostics; namespace MyTestConsole { /// <summary> /// Config の概要の説明です。 /// </summary> public class Config { //private Hashtable dtpServer ; IDictionary tbl1,tbl2; public Config() { tbl1 = (IDictionary)ConfigurationSettings.GetConfig("myGroup/mySettings1"); tbl2 = (IDictionary)ConfigurationSettings.GetConfig("myGroup/mySettings2"); string value1 = (string)tbl1["key1"]; string value2 = (string)tbl2["key1"]; Console.WriteLine("[Sec1/key1]:" + value1 + "[Sec2:key1]:" + value2 ); //impFileName =(NameValueCollection)ConfigurationSettings.GetConfig("ImpFileName"); } } } |
|
投稿日時: 2005-11-16 11:45
<myGroup>
</configSections> を逆にしてみてください |
|
投稿日時: 2005-11-16 19:12
お忙しいところすみません。ありがとうございます。
構成ファイルをご指摘のとおり変更してみたのですが やはりエラーになります。下記のようなエラーです。 この構成ファイルの書き方がまちがっているためなのでしょうか。 何度もお手数をおかけしますが、ご存知でしたら教えていただけないでしょうか。 よろしくお願いいたします。 (エラー内容) 'System.Configuration.ConfigurationException' のハンドルされていない例外が system.dll で発生しました。 追加情報 : This is an unexpected token. The expected token is 'NAME'. Line 11, position 36. 〜〜構成ファイル〜〜 <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="myGroup"> <section name="mySettings1" type="System.Configuration.SingleTagSectionHandler,System" /> <section name="mySettings2" type="System.Configuration.SingleTagSectionHandler,System" /> </sectionGroup> </configSections> <myGroup> <mySettings1 key1="MyApp"/> <mySettings2 key1="value 1"key2="value 2" /> </myGroup> </configuration> |
1