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

查看:211
本文介绍了错误的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的名称),并获得了价值与code以下行:

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天全站免登陆