section
コンソール アプリケーションで、キーと値のペアを取得しようとしていますが、取得できませんでした。これを行うには、次の 2 つの方法があります。
しかし、以下のコードはこのエラーを生成しています: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;
}
}
}