Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get executing assembly name from referenced DLL in C#

Tags:

c#

.net

What is the best way to get the application name (i.e MyApplication.exe) of the executing assembly from a referenced class library in C#?

I need to open the application's app.config to retrieve some appSettings variables for the referenced DLL.

like image 636
Michael Kniskern Avatar asked Nov 07 '08 17:11

Michael Kniskern


1 Answers

To get the answer to the question title:

// Full-name, e.g. MyApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null string exeAssembly = Assembly.GetEntryAssembly().FullName;  // or just the "assembly name" part (e.g. "MyApplication") string exeAssemblyName = Assembly.GetEntryAssembly().GetName().Name; 

As mentioned by @Ben, since you mention wanting to get the configuration information, use the ConfigurationManager class.

like image 66
Ray Hayes Avatar answered Oct 05 '22 11:10

Ray Hayes