Click here to Skip to main content
13,899,972 members
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 17 Oct 2008
Licenced CPOL

Get an Executable Assembly Name

, 17 Oct 2008
Rate this:
Please Sign up or sign in to vote.
Use GetEntryAssembly to obtain an executable's assembly name - even from a DLL.


This little example shows how you can obtain the assembly name of an executable, even if you seek it from a DLL called by that executable.


I was looking for a reliable way to get the assembly name of the original starting executable. I found plenty of examples of using System.Environment.GetCommandLineArgs()[0], but it returns the path to the executable file name, not the assembly name defined in the Project Properties.

Additionally, I did not want the full path, just the name of the assembly, even if the file name had changed. Sure, I could use System.IO.Path.GetFileNameWithoutExtension(path) to get the name, but that would not allow me to express my true OCD Personality Type nature :). If called within the IDE, you would get "ExeName.vshost".

Finally, I wanted to obtain the name of the original executable assembly, even if from a DLL called by the executable. How did I finally satisfy my own personal obsessive nature and find a hackless solution?

Using the code

The GetEntryAssembly() method returns the assembly of the first executable that was executed. I used the following to obtain the assembly name of the original executable:


string name = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;

Visual Basic .NET

Dim name as String = System.Reflection.Assembly.GetEntryAssembly().GetName().Name; 

We could use System.Windows.Forms.Application.ProductName in Visual Basic, but it does not return the assembly name - it returns the assembly Product Name (a slight distinction - again that whole OCD thing :)

If you use this code in a DLL file, it will still return the assembly name of the executable that called on the DLL. I use this method in a generic logging class that I call from many different projects - I would like the entries it makes to contain the assembly name of the program that used the DLL. It even returns the original assembly name when the DLL is called from another DLL that was called by the original EXE! (Whew! Time for medication. :)

The sample application produces these message boxes:


from this executable's assembly:




This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Systems Engineer ThomsonReuters Tax & Accounting
United States United States
I am a Senior System Administrator for a 400+ server ASP farm. With such a large farm and limited staff, our goal is to add as much automation as possible to the system. Most of my programming consists of intelligent slack: spending 2 hours to write a program that handles a reoccurring 10 minute manual job.

You may also be interested in...

Comments and Discussions

QuestionQuestion Pin
Jo_Elena26-Aug-14 5:37
memberJo_Elena26-Aug-14 5:37 
AnswerRe: Question Pin
hayes.adrian2-Jun-15 7:30
memberhayes.adrian2-Jun-15 7:30 
GeneralThanks! Pin
Sergey A Alekseev11-Aug-13 6:42
memberSergey A Alekseev11-Aug-13 6:42 
GeneralMy vote of 1 Pin
KarstenK31-Oct-10 23:53
mveKarstenK31-Oct-10 23:53 
GeneralThanks! Pin
Wes Jones18-May-09 13:24
memberWes Jones18-May-09 13:24 
GeneralHere some code you may find useful [modified] Pin
Ilíon20-Oct-08 4:19
memberIlíon20-Oct-08 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190306.1 | Last Updated 17 Oct 2008
Article Copyright 2008 by hayes.adrian
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid