title: Getting the assembly name for a process started within an app domain
body: <p>I have a service that creates an app domain and starts it:</p>
  
  <pre><code>this._appDomain = AppDomain.CreateDomain(this._appName, AppDomain.CurrentDomain.Evidence, appDomainSetup);
  this._startStopControllerToRun = (IStartStop)this._appDomain.CreateInstanceFromAndUnwrap(assemblyName, this._fullyQualifiedClassName);
  this._startStopControllerToRun.Start();
  </code></pre>
  
  <p>That has been running well for a long time now. The issue is when the controller, started within this app domain, calls a framework logging class. The logger gets the entry assembly name and records that as the source in the event log. This is how the logger gets the source (caller) name:</p>
  
  <pre><code>private static string GetSource()
  {
      try
      {
          var assembly = Assembly.GetEntryAssembly();
  
          // GetEntryAssembly() can return null when called in the context of a unit test project.
          // That can also happen when called from an app hosted in IIS, or even a windows service.
          if (assembly == null)
          {
              // From http://stackoverflow.com/a/14165787/279516:
              assembly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly;
          }
  
          return assembly.GetName().Name;
      }
      catch
      {
          return "Unknown";
      }
  }
  </code></pre>
  
  <p>Before adding that <code>if</code> check, the logger would record "Unknown" for the source. After some research, I added that attempt in the <code>if</code> block. Now the logger records "mscorlib" as the source (entry assembly name).</p>
  
  <p>This is the overview:
  Host -> Controller (running within app domain)</p>
  
  <p>How can I get the name of the assembly (that has the controller) running within the domain?</p>
  
  <p>Note: I also tried this (below), but it gives me the name of the framework where the logging class exists (not the name of the assembly in which the controller is running within the app domain):</p>
  
  <pre><code>assembly = Assembly.GetExecutingAssembly();
  </code></pre>