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

    Question



  • I have a check to make sure the app.config file exists and to report an error if it does not:

    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");
    }


    When I build the solution, the app.config file in is added to the output directory as AppName.exe.config, and if run from outside visual studio AppDomain.CurrentDomain.SetupInformation.ConfigurationFile contains the path C:\path\AppName.exe.config (from within VS it's C:\path\AppName.vshost.exe.config).


    The problem is that if I delete AppName.exe.config, the value is C:\path\Appname.config (no .exe).

    I did a bit of farther experimentation, and if Appname.config exists that file will also work to load my setting values.

    What's going on here?


    It doesn't matter that much which file it looks for as long as it's only one, and that that file is created using visual studio, I just can't be having MyApp.exe.config created by the build, but the missing file error saying MyApp.config is missing.
    Thursday, March 25, 2010 7:39 PM

Answers

  • Hello Dan,

     

    The product team has confirmed that it is a product issue.  AppDomain.CurrentDomain.SetupInformation.ConfigurationFile should always return AppName.exe.config.  

     

    For your follow-up question, we cannot change the default appdomain’s behavior.  However, if we create a new appdomain, we can set an AppDomainSetup.ConfigurationFile to a new location and pass the AppDomainSetup to AppDomain.CreateDomain() method.   http://blogs.msdn.com/suzcook/archive/2003/06/02/57160.aspx. 

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Dan Neely Wednesday, March 31, 2010 3:22 PM
    Wednesday, March 31, 2010 6:18 AM

All replies

  • Hello Dan,

     

    Based on my test, I think you are right because if no AppName.exe.config exists, AppDomain.CurrentDomain.SetupInformation.ConfigurationFile becomes AppName.config.   However, according to Suzanne’s blog, http://blogs.msdn.com/suzcook/archive/2003/06/02/57160.aspx, the default .config is under the process exe’s directory and named the same as the process exe + “.config”.  (AppName.exe.config).  

     

    The default appdomain created by CLR will only load the config file once.  It seems that the AppName.config is the second choice for the default appdomain if AppName.exe.config does not exist.   For the detailed design, I will consult the product team and get back to you as soon as possible.  

     

    Have a nice weekend!

     


    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, March 26, 2010 6:27 AM
  • If this is default appdomain behavior, is there a way to prevent it by explicitly creating the appdomain myself?
    Friday, March 26, 2010 12:33 PM
  • Hello Dan,

     

    The product team has confirmed that it is a product issue.  AppDomain.CurrentDomain.SetupInformation.ConfigurationFile should always return AppName.exe.config.  

     

    For your follow-up question, we cannot change the default appdomain’s behavior.  However, if we create a new appdomain, we can set an AppDomainSetup.ConfigurationFile to a new location and pass the AppDomainSetup to AppDomain.CreateDomain() method.   http://blogs.msdn.com/suzcook/archive/2003/06/02/57160.aspx. 

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Dan Neely Wednesday, March 31, 2010 3:22 PM
    Wednesday, March 31, 2010 6:18 AM
  • Thank you.  Do I need to report this on MSDN Connect's submit visual studio feedback page as well to get it officially logged?
    Wednesday, March 31, 2010 3:29 PM
  • Thanks Dan.  I think the product team has know this issue, so we don't need to report the problem on Microsoft Connect. 

     

    Have a nice weekend!

     

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, April 02, 2010 5:07 AM