Partilhar via


How to find public key token for a .NET DLL or assembly

Many times we need to get the Public key token for a strongly named assembly in .NET. FAQ on that “how to get the public key token?”. Answer is very simple use the .NET Framework tools sn.exe. So open the Visual Studio 2008 Command Prompt and then point to the dll’s folder you want to get the public key,

Use the following command,

sn –T myDLL.dll

This will give you the public key token. Remember one thing this only works if the assembly has to be strongly signed.

Example

C:\WINNT\Microsoft.NET\Framework\v3.5>sn -T EdmGen.exe

Microsoft (R) .NET Framework Strong Name Utility Version 3.5.21022.8

Copyright (c) Microsoft Corporation. All rights reserved.

Public key token is b77a5c561934e089

Namoskar!!!

Comments

  • Anonymous
    May 11, 2009
    That's not fonction with framwork 3.0

  • Anonymous
    June 25, 2009
    Thank you! Why doesn't the MSDN documentation make this obvious?

  • Anonymous
    June 29, 2009
    MSDN is Wiki now, so you can add your inputs there. Please feel free to add any document/notes for others.

  • Anonymous
    February 24, 2010
    We can find the public token key in GAC

  • Anonymous
    March 02, 2010
    The comment has been removed

  • Anonymous
    April 20, 2010
    I couldn't find it at first and then realized the location depends on the version.  Try opening a visual studio command prompt, as it should recognize the sn command

  • Anonymous
    May 04, 2010
    Thanks, this tip helped me out! Felipe

  • Anonymous
    November 01, 2010
    Touche, very good when i needed to find the strongly typed keytoken....tyvm.

  • Anonymous
    March 10, 2011
    Yes, Mark's suggestion worked for me. "Try opening a visual studio command prompt, as it should recognize the sn command" For me the executable is located in a totally different place from what you posted. For me, it's located in the following folder: C:Program FilesVISUALSTUDIO.2005.ENVC (VS2005) C:Program FilesMicrosoft Visual Studio 10.0VC> (VS2010) So using visual studio command prompt, which is not available in newer version will be your best bet.

  • Anonymous
    March 13, 2011
    The location I have specified is for EdmGen.exe not for Command Prompt. You should open the command prompt from program menu if VS

  • Anonymous
    September 14, 2011
    The comment has been removed

  • Anonymous
    November 26, 2011
    WHERE WE USE THIS PUBLIC KEY TOKEN AND WHAT IS THE MAIN USE WITH IT?

  • Anonymous
    March 22, 2012
    Hi I found a quite easy way to do so, even with unsigned assemblies. Open Immediate Window (Alt + Ctrl + I) and write the following command ?System.Reflection.Assembly.LoadFile(@"C:Pathsample.dll").FullName It will also provide you the version no, culture and public key

  • Anonymous
    May 06, 2012
    Inspired by @Amlan's comments, I am using powershell to list the info: ([system.reflection.assembly]::loadfile("c:program filesMicrosoft SQL Server100SDKAssembliesMicrosoft.sqlserver.smo.dll")).FullName This will gives out the following info Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 Thanks @Amlan

  • Anonymous
    October 24, 2012
    Thank You.

  • Anonymous
    November 18, 2012
    Thank You!! Magical tip!!

  • Anonymous
    March 13, 2013
    Thanks much for this post.  Yes, 5 years later people are still reading it.

  • Anonymous
    April 06, 2013
    @Chris F - Thanks a lot glad it helped. My intension is to help community.

  • Anonymous
    April 06, 2013
    @Suja - Thanks a lot and glad!!!

  • Anonymous
    October 23, 2013
    Fantastic - and yes I used the Visual Studio command prompt.

  • Anonymous
    May 08, 2014
    There is no such thing as a VS 2008 command prompt.

  • Anonymous
    October 13, 2016
    Excellent website үou hаve ɦere but Ι was wondering if youu кnew of any community forums tɦat cover thе same topics discussed ɦere?I'd гeally ⅼike to be a pɑrt of community where I can get opinions from other experienced people thzt hare tҺe same interest.If you hav any suggestions, pleaѕе let mе know.Τhank уou!

  • Anonymous
    March 31, 2017
    If all you're interested in is adding an assembly for strong name verification skipping, just use this shell-extension - http://sbytestream.pythonanywhere.com/software/asmprops