我的app.config文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="ProcessConfiguration" type="Configuration.ProcessConfigurationSection, Configuration" />
</configSections>
<ProcessConfiguration>
<processes>
<process name="Process1" />
</processes>
</ProcessConfiguration>
</configuration>
我有以下(单独的)类来获取配置:
namespace Configuration
{
using System.Configuration;
public class ProcessesConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("processes", IsDefaultCollection = false)]
[ConfigurationCollection(typeof(ProcessCollection))]
public ProcessCollection Processes
{
get
{
return (ProcessCollection)base["processes"];
}
}
}
}
namespace Configuration
{
using System.Configuration;
public class ProcessCollection : ConfigurationElementCollection
{
public ProcessConfig this[int index]
{
get
{
return (ProcessConfig)BaseGet(index);
}
set
{
BaseAdd(index, value);
}
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((ProcessConfig)element).Name;
}
protected override ConfigurationElement CreateNewElement()
{
return new ProcessConfig();
}
}
}
namespace Configuration
{
using System.Configuration;
public class ProcessConfig : ConfigurationElement
{
[ConfigurationProperty("name", IsRequired = true, IsKey = true)]
public string Name
{
get
{
return (string)this["name"];
}
set
{
this["name"] = value;
}
}
}
}
但是,当我点击这行代码时:
var processConfigurationSection = ConfigurationManager.GetSection("ProcessConfiguration") as ProcessesConfigurationSection;
我收到错误消息:
为 ProcessConfiguration 创建配置节处理程序时出错:无法从程序集“Configuration”加载类型“Configuration.ProcessConfigurationSection”。
我完全被难住了,如果有人能帮助我,我会非常感激。