How do I find the fully qualified name of an assembly?
Asked Answered
I

10

55

How do I find out the fully qualified name of my assembly such as:

MyNamespace.MyAssembly, version=1.0.3300.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089

I've managed to get my PublicKeyToken using the sn.exe in the SDK, but I'ld like to easily get the full qualified name.

Iridescent answered 18/3, 2009 at 14:21 Comment(0)
M
35

If you can load the assembly into a .NET application, you can do:

typeof(SomeTypeInTheAssembly).Assembly.FullName

If you cannot then you can use ildasm.exe and it will be in there somewhere:

ildasm.exe MyAssembly.dll /text
Macaque answered 18/3, 2009 at 14:23 Comment(5)
Actually, that gives you the assembly in which SomeTypeInTheAssembly resides, which you may not have at compile time.Arthurarthurian
And I'm not sure "in there somewhere" qualifies as an answer. That ildasm command results in a wall of text, not well formatted. Several of the suggestions below are more complete.Twirp
You can search the output for "MyAssembly, Version=" to find it. If you have grep installed: ildasm.exe MyAssembly.dll /text | grep -A 1 "MyAssembly, Version="Triennial
Unfortunately when the Assembly is obfuscated then the solution with ildasm.exe will not work.Shroyer
ildasm.exe MyAssembly.dll /text does NOT contain full assembly name anywhere in the text. This method is misleading and inaccurate.Bareback
R
153

This is a shameless copy-paste from I Note It Down and is a simple way to get the FQN for the project output:

Open Visual Studio
Go to Tools –> External Tools –> Add
    Title: Get Qualified Assembly Name
    Command: Powershell.exe
    Arguments: -command "[System.Reflection.AssemblyName]::GetAssemblyName(\"$(TargetPath)\").FullName"
    Check "Use Output Window".

The new tool appears under Tools –> Get Qualified Assembly Name. When the menu item is selected, the assembly name is given in the output window.

Reciprocation answered 1/7, 2013 at 2:16 Comment(5)
Microsoft, The year is 2015. Please provide us with a better alternative to get the fully qualified assembly name.Plainspoken
This should be the selected answerNoma
Seconding @M3579's comment, have some bounty.Latini
This is the most convenient way of checking this ever!Picker
The question did not specify "for the current project." I suspect the author wants this for any assembly, including dependencies.Kono
M
35

If you can load the assembly into a .NET application, you can do:

typeof(SomeTypeInTheAssembly).Assembly.FullName

If you cannot then you can use ildasm.exe and it will be in there somewhere:

ildasm.exe MyAssembly.dll /text
Macaque answered 18/3, 2009 at 14:23 Comment(5)
Actually, that gives you the assembly in which SomeTypeInTheAssembly resides, which you may not have at compile time.Arthurarthurian
And I'm not sure "in there somewhere" qualifies as an answer. That ildasm command results in a wall of text, not well formatted. Several of the suggestions below are more complete.Twirp
You can search the output for "MyAssembly, Version=" to find it. If you have grep installed: ildasm.exe MyAssembly.dll /text | grep -A 1 "MyAssembly, Version="Triennial
Unfortunately when the Assembly is obfuscated then the solution with ildasm.exe will not work.Shroyer
ildasm.exe MyAssembly.dll /text does NOT contain full assembly name anywhere in the text. This method is misleading and inaccurate.Bareback
F
26

Late to the party, but googled some more about this issue and found this page:

He describes a powershell function that can do this. So. I've never ever used powershell before, but I thought I'd give it a try:

C:\> cd PATH_TO_ASSEMBLY   
C:\PATH_TO_ASSEMBLY>powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\PATH_TO_ASSEMBLY> [System.Reflection.AssemblyName]::GetAssemblyName('System.Data.SQLite.dll').FullName
System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
PS C:\PATH_TO_ASSEMBLY>

This does the trick mentioned in other answers by using code, except you don't have to create a project to do this - just type away at the prompt ;)

Follow answered 7/3, 2013 at 12:1 Comment(4)
Thanks! Ended using the C# version of this AssemblyName.GetAssemblyName(assemblyPath).FullNameThrifty
And a suggestion is to use the full path to the assembly name and not just the assembly name. FWIW, it doesn't work if you give that way and even if you are in the same directory as the assembly.Hangout
This seems to try to load the file from my home directory rather than the current directory. PS C:\projects\sphw\bin\Debug> [System.Reflection.AssemblyName]::GetAssemblyName('sphw.dll').FullName gives the error MethodInvocationException: Exception calling "GetAssemblyName" with "1" argument(s): "Could not find file 'C:\Users\mikeblas\sphw.dll'." Why is that?Pointed
@Pointed I'm just guessing here, but maybe you need to load the assembly first. I'm guessing System.Data.SQLite just happened to either already be loaded or was within the "searchpath" for assemblies.Follow
A
9

Use Assembly.GetExecutingAssembly() to get the current assembly, use Assembly.GetEntryAssembly() to get the assembly that started it all, or use Assembly.GetCallingAssembly() to get the assembly of the code that called your function (one up in the stack).

Once you have the right assembly, use the FullName property, as indicated in other answers.

Arthurarthurian answered 18/3, 2009 at 14:27 Comment(0)
U
6

Also if you're looking for the Fully Qualified Name for an assembly already in the GAC you can launch a Visual Studio Command Prompt (easiest way to set the correct paths) and use gacutil /l to list all assemblies with their respective FQNs. Use gacutil /l <yourassemblyname> to filter the list to more easily find what you're looking for.

Uremia answered 16/8, 2011 at 16:20 Comment(0)
C
6

You can also use open source ILSpy, after you load your assembly it's full name will be diplayed in comments at the top of code window

Coexecutor answered 27/8, 2012 at 9:52 Comment(0)
D
5

If you load the assembly (DLL, EXE, etc.) in Reflector it will tell you the full strong name at the bottom.

Disseminate answered 18/3, 2009 at 14:25 Comment(6)
This answer is out of line, he was not asking for a $118 plug-in to find this out.Maurist
At the time this was posted Reflector was free.Disseminate
ILSpy is a free alternative for Reflector which can be used to find the fully qualified name of an assembly.Hotpress
Old .Net Reflector 6.8.2.5 is free and it is working.Buttress
Nowadays dotPeek (by JetBrains) is the best free alternative for this purpose.Industrious
dotPeek does NOT display the full name, or even the public key.Kono
P
4

JetBrains dotPeek or Telerik JustDecompile are quite good. Just open the DLL and you have the name right away.

Prosit answered 14/3, 2013 at 15:27 Comment(0)
D
2

Being old-school and liking cmd better than powershell, I wrote myself this batch script to do it:

@REM fqn.bat <dll_path>
powershell -command "([system.reflection.assembly]::loadfile('%~f1')).FullName"

The %~f1 expands the first parameter to be an absolute path, so running:

fqn mydll.dll 

Will print the fully-qualified name you want.

Dorsett answered 24/1, 2019 at 16:31 Comment(0)
C
1

Couple ways.

In code:

Assembly.FullName e.g.

typeof(Thingy).Assembly.FullName

or, if its an installed assembly, from the GAC using the steps in this post on msdn.

Cabalist answered 18/3, 2009 at 14:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.