Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get web application assembly name, regardless of current executing assembly

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 but it seems to be always null in web apps, and GetExecuting\GetCallingAssebly return my referenced assembly, not the one from the web app.


Long explanation:

I wrote a custom Settings Provider, that instead of reading configuration from the app config file, it gets the settings from a centralized configuration service.

The custom provider is in a separate assembly so it can be used by the different applications.

The ApplicationName property needs to be overriden with the app assembly name.

The way to use the provider is though a .net custom attribute, so I can't send any params to it.

Since non of the Assembly.Get*Assembly methods seem to work, the only thing a I can think of is requiring an appSetting with the app name for web apps, but I'm not really happy with that. Any help with this is appreciated, thanks!

like image 708
Pablote Avatar asked Sep 18 '11 17:09

Pablote


2 Answers

Try

BuildManager.GetGlobalAsaxType().BaseType.Assembly
like image 142
Vasiliy Shiryaev Avatar answered Oct 29 '22 16:10

Vasiliy Shiryaev


You can use

HttpContext.Current.ApplicationInstance.GetType().Assembly
like image 31
SLaks Avatar answered Oct 29 '22 16:10

SLaks