繁体   English   中英

为什么我的应用程序同时寻找MyApp.exe.config和MyApp.config来查找app.config文件

[英]Why does my application look for both MyApp.exe.config and MyApp.config to find the app.config file

我进行检查以确保app.config文件存在,如果不存在,则报告错误:

System.Windows.Forms.MessageBox.Show(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
if (!File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
{

    throw new ConfigurationErrorsException("Unable to find configuration file.  File is expected at location:  "
    + AppDomain.CurrentDomain.SetupInformation.ConfigurationFile + "\n");
}

当我构建解决方案时,其中的app.config文件将作为AppName.exe.config添加到输出目录中,并且如果从外部Visual Studio AppDomain.CurrentDomain.SetupInformation.ConfigurationFile运行,则包含路径C:\\ path \\ AppName.exe .config(在VS中为C:\\ path \\ AppName.vshost.exe.config)。 如果我删除AppName.exe.config,则值为C:\\ path \\ Appname.config(无.exe)。

我做了一些进一步的实验,如果Appname.config存在,该文件也将加载我的设置值。

这里发生了什么? 为了错误报告的目的,我需要使所有内容保持一致。

当我没有得到答案时,我在MSDN上重新发布了此内容。 Microsoft已经确认这是一个错误。 官方的解决方法是创建我自己的应用程序域,而不使用默认域。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM