title: Accessing information in the AssemblyInfo.cs using Reflection in a Web Site
body: <p>I have created a DLL that will gather information from the AssemblyInfo.cs.  In the class constructor I am using Reflection to get the top-most application that is running.</p>
  
  <pre><code>public class AppInfo()
  {
      public AppInfo()
      {
          System.Reflection.Assembly assembly =
              System.Reflection.Assembly.GetEntryAssembly();
          if (assembly == null)
              assembly = System.Reflection.Assembly.GetCallingAssembly();
  
  
          //code to gather needed information
      }
  }
  </code></pre>
  
  <p>How this is intended to be used is if I call this from any DLL in a given application, MyApp, that lets say the name will always be 'MyApp'.  Retrieving that information is not a problem and it works great in Windows Services and Windows Applications.  My question is this:
  <strong>How do I get the Assembly of the top-most Website?</strong></p>
  
  <p>I have found a few articles and I can get the information in the Global.asax.cs by moving the AssemblyInfo.cs for the Website out of the App_Code folder and into the root of the Website.  Then by adding a compilerOption to the physical path of the AssemblyInfo.cs</p>
  
  <pre><code>&lt;compiler
  language="c#;cs;csharp"
  extension=".cs"
  compilerOptions="C:\Sandbox\MyWebSite\AssemblyInfo.cs"
  type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4"&gt;
  </code></pre>
  
  <p>Using that I am able to retrieve information in the AssemblyInfo.cs for the Website through <code>System.Reflection.Assembly.GetExecutingAssembly()</code>.  Now I can overload the constructor of my <code>AppInfo</code> class to accept an <code>Assembly</code> and retrieve information that way, but if another DLL that is used by <code>MyWebSite</code> creates a <code>new AppInfo()</code> I will get the assembly information of that DLL instead of the parent Website.</p>
  
  <p>I know that if I was working with Web Apps instead of Web Sites I wouldn't have this issue, but for reasons I won't go into I am not able to use Web Apps.  Any suggestions on how I can read information from the AssemblyInfo.cs of the Website I'm running in no matter what DLL I'm in?</p>
  
  <p><strong>EDIT:</strong>  I need this to work for Web Sites, Windows Apps and Windows Services</p>