Calling Assembly to get Application Name

visual basic console application samples
visual basic forms examples
vb net application
vb net practical programs
net program
vb net programs examples
vb net programs with coding
visual basic example

I have a console application (MyProgram.EXE) that references a Utilities assembly.

In my Utilities assembly, I have code that does:

Dim asm As Assembly = Assembly.GetExecutingAssembly()
Dim location As String = asm.Location
Dim appName As String = System.IO.Path.GetDirectoryName(location)
Conole.WriteLine("AppName is: {0}", appName)

When I call it from MyProgram.EXE, I receive "AppName is: Utilities.dll"

What I want is "AppName is: MyProgram.EXE"

What am I doing wrong?

Use GetEntryAssembly() instead to get the assembly containing the entry point.

The better way to do it is using System.Environment.CommandLine property instead.


Dim location As String = System.Environment.GetCommandLineArgs()(0)
Dim appName As String = System.IO.Path.GetFileName(location)
Conole.WriteLine("AppName is: {0}", appName)

By the way, you want to use GetFileName instead of GetDirectoryName

Calling Assembly to get Application Name, I have a console application ( MyProgram.EXE ) that references a Utilities assembly. In my Utilities assembly, I have code that does: Dim asm As Assembly​  Dim int1 As Integer ' Set the Type instance to the target class type. Dim type1 As Type =int1.GetType () ' Instantiate an Assembly class to the assembly housing the Integer type. Dim sampleAssembly = Assembly.GetAssembly (int1.GetType ()) ' Display the name of the assembly that is calling the method.

Since it is VB.NET you were asking about, you can extract this information easily from the 'My' namespace as shown below:


Assembly.GetCallingAssembly Method (System.Reflection , › › .NET › .NET guide › Assemblies in .NET You can use the AssemblyName class to get the assembly name, provided you have the full name for the assembly: AssemblyName.GetAssemblyName(Assembly.GetExecutingAssembly().FullName).Name or. AssemblyName.GetAssemblyName(e.Source).Name MSDN Reference - AssemblyName Class

I use:

CallingAppName = System.Reflection.Assembly.GetEntryAssembly.GetName().Name

How to: Find an assembly's fully qualified name, This article shows you how to get the fully qualified name of a . in the global assembly cache, use the Global Assembly Cache tool (Gacutil.exe). If you know the assembly's file system path, you can call the static (C#) or  Is there a way in C# to get the Assembly of the calling method? (Not the current method.) i.e. I want the executing assembly, one above in the call stack.

In my case, I didn't have access to My.Application, probably because I was in a global class, so I used:

AppName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name

Calling Assembly to get Application Name VB.NET - .net - iOS, I have a console application (MyProgram.EXE) that references a Utilities assembly. In my Utilities assembly, I have code that does: Dim asm As Assembly​  Evidence^ asEvidence = currentDomain->Evidence; //Load the assembly from the application directory using a simple name. //Create an assembly called CustomLibrary to run this sample. currentDomain->Load( "CustomLibrary", asEvidence ); //Make an array for the list of assemblies. array<Assembly^>^assems = currentDomain->GetAssemblies(); //List the assemblies in the current application domain.

Get an Executable Assembly Name, 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  If you want the name of the parent EXE and not the referenced DLL assembly - you will need to use this: Assembly.GetEntryAssembly().GetName().Name This will return the EXE name (minus the .EXE part). Using GetExecutingAssembly() is not right as per the OP's question (first paragraph of it!) as it will return the DLL name.

Getting to Know Your Assembly by Name and Number -- Visual , vb file that Visual Studio adds to your new project. This file includes human-​friendly fields that help identify the assembly: Name, Description,  If you call this in Application library you will get application version and if call this in a DLL then will get that DLL version. So in my opinion System.Reflection.Assembly.GetEntryAssembly().GetName().Version; is currect function to use.

The Definitive Guide to the .NET Compact Framework, It's not a simple task to get the path or name of your application at runtime. when you have one assembly started or loaded by a parent, or calling, assembly. The property Name of the returned Assembly instance GetName () call is what you need, and does not include the ".exe" part. Also tested on Mono/Linux with expected result. Assembly.GetName ().Name – Hatoru Hansou Jan 22 '14 at 23:54 1

  • Wow where did all those br's come from in my edit.
  • Why is System.Environment.CommandLine better than GetEntryAssembly()?
  • Because GetEntryAssembly() can return null. See:…
  • also (per…): "The GetEntryAssembly method also returns null if you are running a WCF service application in debug mode, under IIS. This is, admittedly, a rare situation that only a developer would encounter. – Gravitas Nov 10 '10 at 10:39"
  • This will also get the assembly of the referenced DLL, not the calling (parent) module.