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.
Specifically:
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