我很难尝试访问我的配置文件中的自定义配置部分。
正在从作为插件加载的 .dll 读取配置文件。我使用配置部分设计器VS 插件创建了配置和必要的代码。
命名空间是“ImportConfiguration”。ConfigurationSection 类是“ImportWorkflows”。程序集是 ImportEPDMAddin。
xml:
<configSections>
<section name="importWorkflows" type="ImportConfiguration.ImportWorkflows, ImportEPDMAddin"/>
</configSections>
每当我尝试读取配置时,都会收到错误消息:
为 importWorkflows 创建配置节处理程序时出错:无法加载文件或程序集“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;
我也尝试过使用简单的 NameValueFileSectionHandler,但我收到一个异常,说它无法加载文件或程序集“系统”。
我已经阅读了许多博客文章和文章,听起来可以为 dll 读取配置文件,但我就是无法让它工作。有任何想法吗?谢谢。