title: NServiceBus Host Console Using Wrong App Config
body: <p><strong>tldr - NServiceBus.Host.exe hijacks my app.config in debug mode</strong></p>
  
  <p>When using the configuration manager, I am not able to access the appSettings for the project I am calling code within. </p>
  
  <p>I am using self host with the NServiceBus Host nuget package, version 4.4.2</p>
  
  <pre><code>namespace EnrollmentService.Reporting
  {
      public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
      {
          public EndpointConfig()
          {
              //TODO: WHAT IS HAPPPEEENNIIINNNGG
              var url = ConfigurationManager.AppSettings["configurationKey"];
  
              var config = ConfigurationManager.OpenExeConfiguration("EnrollmentService.Reporting.dll");
  
              var nsbHostConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
          }
      }
  }
  </code></pre>
  
  <p>The variable 'url' comes back null.
  The variable 'config' is what used to be the configuration context for this application.
  The variable 'nsbHostConfig' is the actual configuration context for the application.</p>
  
  <p>Again, the expected path for the configuration is "EnrollmentService.Reporting.dll.config", but the actual path is "NServiceBus.Host.exe.config". The NServiceBus config file doesn't exist.</p>
  
  <p>This seems to be a machine specific problem, as it works as expected, using the "*.dll.config" on other machines. </p>
  
  <p>It makes sense to me that the executable that ends up calling code should be the config for the "running" application, but previously, it was using the expected *.dll.config. It also makes sense to me that NServiceBus would be changing the configuration context, because for debugging purposes, the host runs as a console app, but for deployments, it is installed as a windows service. It would be silly to need to swap out your config files in your bin whenever you needed to develop.</p>
  
  <p><strong><em>Why would the operating context for my self host application switch to use the NServiceBus executable's config?</em></strong></p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p><strong>Below, is what SHOULD be happening, but it is not</strong></p>
  
  <p><a href="https://github.com/Particular/NServiceBus.Host/blob/develop/src/NServiceBus.Hosting.Windows/EndpointTypeDeterminer.cs" rel="nofollow">https://github.com/Particular/NServiceBus.Host/blob/develop/src/NServiceBus.Hosting.Windows/EndpointTypeDeterminer.cs</a> </p>
  
  <p>Looking at the NServiceBus source code, if your EndpointType is not specified in your app.config, the EndpointTypeDeterminer.cs finds your EndpointType by assembly scanning for the type IConfigureThisEndpoint. It then finds the path to your app.config file by calling the below code on the type it finds: </p>
  
  <pre><code>public string EndpointConfigurationFile
  {
      get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, type.Assembly.ManifestModule.Name + ".config"); }
  }
  </code></pre>
  
  <p>That configuration file path is then used through System.AppDomainSetup to call System.AppDomain.CreateDomain</p>