在控制台应用程序中,我试图获取section
键值对,但我做不到。有两种方法可以做到这一点:
但是下面的代码会产生这个错误: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;
}
}
}