加载了错误的App.config [英] Wrong App.config being loaded

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

问题描述

我有一个.NET 3.5类库,它读取所需的值的App.config文件。它可以拉我的配置值很好,当我在Visual Studio中测试它。要测试它,我只是将项目更改为控制台应用程序并执行方法调用。

I have a .NET 3.5 class library I built that reads an App.config file for values it needs. It can pull the config values just fine when I test it in Visual Studio. To test it, I just change the project to a console application and execute a method call.

我需要从许多其他.NET程序调用此类库,并且我想类库是自给自足的(我应该能够从任何其他程序调用它,它应该使用自己的配置文件,不知道任何调用配置文件等)。

I have the need to call this class library from many other .NET programs, and I want the class library to be self sufficient (I should be able to call it from any other program, and it should use its own config file, not know about any calling config file etc.).

我可以添加一个引用dll(因为我仍然是开发我使用VS 2008,没有投入任何东西到GAC),但App.config类库正在读取的是来自调用程序的App.config,而不是类库的App.config。

I can add a reference to the dll (since I am still development I am using VS 2008, haven't thrown anything into the GAC yet) but the App.config that the class library is reading is from the calling program's App.config, not the class library's App.config.

类库dll的配置文件位于同一目录,所以它应该能够找到它只是罚款,和调用应用程序命名不同。我使用App.config中的标准键值对(例如配置文件myClassLibrary.dll.config的名称),并使用以下代码行获取值:

The class library dll has it's config file in the same directory, so it should be able to find it just fine, and the calling application is named differently. I am using the standard key value pairs in the App.config (e.g. name of config file myClassLibrary.dll.config) and getting values out with the following line of code:

String myVal = ConfigurationSettings.AppSettings["myConfigSetting"];

有人知道如何解决这个问题吗?

Does anyone know how to fix this?

推荐答案

C#中的应用程序域只能有一个程序集级别的app.config文件。 请参阅MSDN 。可执行文件将始终启动AppDomain,并且默认情况下查找名为:EXECUTABLE_NAME.config的配置文件。例如,SampleApp01.exe将查找SampleApp01.exe.config作为其配置文件。

An app domain in C# can have only one assembly level app.config file. See here on MSDN. An executable will always start up an AppDomain and by default look for a config file with name: EXECUTABLE_NAME.config. For example, SampleApp01.exe will look for SampleApp01.exe.config as its configuration file.

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

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