App.config中仅调试时读 [英] App.config only read when debugging

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

问题描述

我目前经历,我一直没能解决的问题。

I am currently experiencing an issue that I haven't been able to resolve.

我有一个应用程序,我有这个code:

I have an application where I have this code:

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "App.config");
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile = Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, "App.config");
MessageBox.Show(ConfigurationSettings.AppSettings.Count.ToString());

配置文件确实叫App.config的应用程序文件夹(我这样做是因为我有两个应用程序读取/修改相同的配置文件)。

The configuration file is indeed called App.config in the application folder (I am doing this because I have two applications reading/modifying the same config file).

当我启动其中任何一个通过Visual Studio调试器,它正确地告诉我,我有11 AppSettings的。然而,当调试器之外运行,我得到0。

When I start either of them through the Visual Studio Debugger, it correctly tells me that I have 11 appsettings. However, when run outside of the debugger, I get 0.

什么可能是错在这里? 我100%肯定这code在过去的工作。

What might be wrong here? I am 100% sure that this code has worked in the past.

推荐答案

我终于能够解决它自己现在。解决的办法是通过

I was finally able to solve it myself right now. The solution is to access the configuration settings through

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

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

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