Is is possible to get the assembly name of an ASP.NET web application, from a referenced assembly??
Assembly.GetEntryAssembly worked fine in desktop and console apps
I know this is an old question but this was my approach to a somewhat similar situation. In my case a was using another assembly for formatting a string with the version to show for multiple programs that have the same core.
Version v = null;
var a = Assembly.GetEntryAssembly() ?? GetWebEntryAssembly() ?? Assembly.GetExecutingAssembly();
SnapshotVersion = FileVersionInfo.GetVersionInfo(a.Location).ProductVersion;
if (ApplicationDeployment.IsNetworkDeployed)
{
var d = ApplicationDeployment.CurrentDeployment;
v = d.CurrentVersion;
v = new Version(v.Major, v.Minor, v.Revision);
}
else
v = a.GetName().Version;
if (v != null)
version = string.Format("{0}.{1}.{2}", v.Major, v.Minor, v.Build);
Because this is in a static constructor all I needed to do was to call any property of this static class from the Web Application and then find the last calling assembly that is different from the assembly that the static class is on. This was achieve with the method GetWebEntryAssembly.
private static Assembly GetWebEntryAssembly()
{
var frames = new StackTrace().GetFrames();
var i = frames.FirstOrDefault(c => Assembly.GetAssembly(c.GetMethod().DeclaringType).FullName != Assembly.GetExecutingAssembly().FullName).GetMethod().DeclaringType;
return Assembly.GetAssembly(i);
}
Try
BuildManager.GetGlobalAsaxType().BaseType.Assembly
You can use
HttpContext.Current.ApplicationInstance.GetType().Assembly