小编ehc*_*ian的帖子

自定义配置部分:无法加载文件或程序集

我在配置文件中尝试访问自定义配置部分非常困难.

正在从作为插件加载的.dll读取配置文件.我使用Configuration Section Designer VS addin 创建了配置和必要的代码.

命名空间是"ImportConfiguration".ConfigurationSection类是"ImportWorkflows".程序集是ImportEPDMAddin.

xml:

  <configSections>
    <section name="importWorkflows" type="ImportConfiguration.ImportWorkflows, ImportEPDMAddin"/>
  </configSections>
Run Code Online (Sandbox Code Playgroud)

每当我尝试读取配置时,我都会收到错误:

为importWorkflow创建配置节处理程序时出错:无法加载文件或程序集"ImportEPDMAddin.dll"或其依赖项之一.该系统找不到指定的文件.

dll不会与可执行文件驻留在同一目录中,因为加载插件的软件将dll和它的依赖项放在它自己的目录中.(我无法控制.)

我将单例实例的代码编辑为以下内容:

string path = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
path = path.Replace("file:///", "");
System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(path);
return configuration.GetSection(ImportWorkflowsSectionName) as ImportConfiguration.ImportWorkflows;
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用一个简单的NameValueFileSectionHandler,但我得到一个例外,说它无法加载文件或程序集'System'.

我已经阅读了大量的博客文章和文章,听起来有可能为dll读取配置文件,但我无法让它工作.有任何想法吗?谢谢.

c# config

21
推荐指数
2
解决办法
2万
查看次数

KeyValuePair键上的相交列表?

如何根据键输入两个KeyValuePairs列表?我试过了:

List<KeyValuePair<string, string>> listA = new List<KeyValuePair<string, string>>();
List<KeyValuePair<string, string>> listB = new List<KeyValuePair<string, string>>();
...
var result = listA.Intersect(listB);
Run Code Online (Sandbox Code Playgroud)

这预计不起作用.我是否需要根据键编写自己的比较器,或者使用LINQ/Lambda是否有一种简单的方法?

谢谢!

c# linq lambda list

3
推荐指数
2
解决办法
1736
查看次数

标签 统计

c# ×2

config ×1

lambda ×1

linq ×1

list ×1