作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我的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;
我收到错误信息:
An error occurred creating the configuration section handler for ProcessConfiguration: Could not load type 'Configuration.ProcessConfigurationSection' from assembly 'Configuration'.
我完全被难住了,如果有人能帮助我,我将不胜感激。
最佳答案
行内:
<section name="ProcessConfiguration" type="Configuration.ProcessConfigurationSection, Configuration" />
名称“Configuration”应该指的是您正在构建的 DLL,请尝试检查并在需要时进行更正。
另外我认为你可能有错字,在你的代码中类型名称是:
ProcessesConfigurationSection
(注意流程与流程)
关于c# - ConfigurationManager.GetSection 给出错误 "Could not load type....from assembly...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19095215/
我是一名优秀的程序员,十分优秀!