【问题标题】:Custom ConfigurationSection type not loading correctly自定义 ConfigurationSection 类型未正确加载
【发布时间】:2010-11-24 16:28:21
【问题描述】:

每次我为此自定义部分执行ConfigurationManager.GetSection("registeredPlugIns") 时都会收到此错误:

为注册插件创建配置节处理程序时出错:

无法加载类型“Engine.PlugInArch.PlugInConfigurationSection” 从程序集'System.Configuration,版本=2.0.0.0,文化=中性, PublicKeyToken=b03f5f7f11d50a3a'。

为什么它试图从System.Configuration 加载类型而不是我要求它加载的程序集?

这是我的部分代码:

namespace Engine.PlugInArch
{
    public class PlugInConfigurationSection : ConfigurationSection
    {
        [ConfigurationProperty("plugIns", IsDefaultCollection = false),
         ConfigurationCollection(typeof(PlugInCollection), AddItemName = "addPlugin")]
        public PlugInCollection PlugIns
        {
            get { return this["plugIns"] as PlugInCollection; }
        }

    }
}

这是我的 app.config

<configuration>
    <configSections>
    <section name="registeredPlugIns" type="Engine.PlugInArch.PlugInConfigurationSection, Engine"/>
    </configSections>
        ...
    <registeredPlugIns>
       <plugIns>
           <addPlugIn DllName="ProcessorPlugin.dll"/>
       </plugIns>
     </registeredPlugIns>

</configuration>

【问题讨论】:

    标签: c# .net configuration


    【解决方案1】:

    您的 dll 是否称为 Engine.dll?我认为不是,这就是问题所在。

    好的,从 sysinternals 运行 procmon。将过滤器设置为您的进程名称,并过滤结果 =“未找到名称”。您将看到它正在寻找 Engine.dll 或 Engine.exe 的条目。查看它在哪里寻找它,很可能该文件需要复制到运行文件夹中。

    【讨论】:

    • 其实是Engine.exe 有关系吗?他们在引用此 app.config 的程序集中键入。
    • 当我将它设置为仅查找 Engine 时,它​​会查找 Engine.dll(它不存在)。当我将它设置为 Engine.exe 时,它​​会查找 Engine.exe.dll。啊。我想我只需要将这种类型移出 .exe。
    • 我添加了 allowExeDefinition="MachineToApplication" ,这似乎可以解决问题。感谢您的帮助。
    • &lt;section name="registeredPlugIns" type="Engine.PlugInArch.PlugInConfigurationSection, Engine" allowExeDefinition="MachineToApplication" /&gt; 依然爱你.Net!
    猜你喜欢
    • 1970-01-01
    • 2010-12-18
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多