1

sectionコンソール アプリケーションで、キーと値のペアを取得しようとしていますが、取得できませんでした。これを行うには、次の 2 つの方法があります。

  1. 構成セクション
  2. IConfigurationSectionHandler

しかし、以下のコードはこのエラーを生成しています:Configuration system failed to initialize どこで間違いを犯していますか?

コードは次のとおりです。 app.config

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="testGroupName">
      <section name="secName" type="TestAssemblyConfigReader.TestConfigReader"/>
    </sectionGroup>
  </configSections>

  <testGrupAdi>
    <secName anahtar="deger" />
  </testGrupAdi>
</configuration>

構成リーダー クラス:

using System.Configuration;

namespace TestAssemblyConfigReader
{
    public class TestConfigReader : ConfigurationSection
    {
        public TestConfigReader()
        {

        }

        [ConfigurationProperty("secName")]
        public string SecName
        {
            get
            {
                return (string)this["secName"];
            }
            set
            {
                this["secName"] = value;
            }
        }
    }
}

コンソール アプリケーション:

using System.Configuration;
using TestAssemblyConfigReader;

namespace ca_FMC.Turkiye.Lib.SVN
{
    class Program
    {
        static void Main(string[] args)
        {
            TestConfigReader serviceConfigSection = ConfigurationManager.GetSection("testGroupName") as TestConfigReader;
        }
    }
}
4

1 に答える 1

0

testGroupNameこんにちはとの間の不一致を削除しますtestGrupAdi

これを使って

<configuration>
  <configSections>
    <sectionGroup name="testGroupName">
      <section name="secName" type="TestAssemblyConfigReader.TestConfigReader"/>
    </sectionGroup>
  </configSections>

  <testGroupName>
    <secName anahtar="deger" />
  </testGroupName>
</configuration>
于 2012-06-25T17:08:24.863 に答える