App.config为dll [英] App.config for dll

查看:137
本文介绍了App.config为dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个动态加载dll的引擎(无论位于某个目录中),并通过反射调用工作流类。

We have an "engine" that loads dlls dynamically (whatever is located in a certain directory) and calls Workflow classes from them by way of reflection.

我们现在有一些新的工作流程需要访问数据库,所以我想我将一个配置文件放在dll目录。

We now have some new Workflows that require access to a database, so I figured that I would put a config file in the dll directory.

但是由于某些原因,我的工作流程只是'看到配置文件。

But for some reason my Workflows just don't see the config file.

<configuration>
  <appSettings>
      <add key="ConnectString" value="Data Source=officeserver;Database=mydatabase;User ID=officeuser;Password=officeuser;" />
  </appSettings>
</configuration>

给定上述配置文件,以下代码打印一个空字符串:

Given the above config file, the following code prints an empty string:

Console.WriteLine(ConfigurationManager.AppSettings["ConnectString"]);

我想我想要的只是指定一个配置文件名,但我在这里遇到问题。我只是没有得到结果。
任何人都有任何指针?

I think what I want is to just specify a config filename, but I'm having problems here. I'm just not getting results. Anyone have any pointers?

推荐答案

如果您的代码示例阅读AppSettings在您的DLL中,那么它将尝试读取应用程序的配置文件,而不是DLL的配置文件。这是因为您使用Reflection来执行代码。

If your code sample for reading the AppSettings is in your DLL, then it will attempt to read the config file for the application and not the config file for the DLL. This is because you're using Reflection to execute the code.

这篇关于App.config为dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆