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

C# 为什么我的应用程序同时查找MyApp.exe.config和MyApp.config来查找app.config文件,c#,app-config,C#,App Config,我进行了检查,以确保app.config文件存在,如果不存在,则报告错误: System.Windows.Forms.MessageBox.Show(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); if (!File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)) { throw new ConfigurationErrors

我进行了检查,以确保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(从内部到C:\path\AppName.vshost.exe.config)。如果删除AppName.exe.config,则值为C:\path\AppName.config(no.exe)

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

这是怎么回事?为了报告错误,我需要所有内容都保持一致。

当我没有得到答案时,我重新发布了这篇文章。微软已经确认这是一个bug。官方的解决办法是创建我自己的应用程序域,而不是使用默认的应用程序域。

当我没有得到答案时,我重新发布了这个应用程序域。微软已经确认这是一个bug。官方的解决办法是创建我自己的应用程序域,而不是使用默认的应用程序域