How to Determine the Public Key Token of an Assembly

Often times we need to reference an assembly in our code that requires that we specify the PublicKeyToken of that assembly. The problem is, determining the Public Key Token of an assembly isn’t as intuitive as you’d think.

This page will show you how to determine the Public Key Token of a given assembly.

If you have installed the Microsoft SDK, you will have a tool named “Strong Name Tool” (the runtime name is “sn.exe”).

The Strong Name tool helps sign assemblies with strong names. Sn.exe provides options for key management, signature generation, and signature verification.

In addition to signing your assemblies, the sn.exe tool will display the public key token for a given assembly via its “-T” switch.

Here’s how to use sn.exe to determine the PKT of an assembly:

For this example, we will use the System.Data.Linq as our assembly.

  1. Open a Visual Studio Command Prompt
  2. Determine the location of your assembly by entering “where System.Data.Linq.dll”
  3. Copy the directory path of the assembly
  4. Change the prompt’s directory location by pasting the directory path you copied in the previous step
  5. Execute the Strong Name Tool -T command by entering “sn -T System.Data.Linq.dll”
  6. The Public key token will be displayed in the command window.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s