Home » Development » How to find out the Public Key Token for an assembly (DLL) file?

How to find out the Public Key Token for an assembly (DLL) file?

In your ASP.NET project, you may need to use public key token of an assembly file while adding it as a reference. Here is an example reference declaration from project.csproj file:

<Reference Include="Oracle.DataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86">
  <SpecificVersion>False</SpecificVersion> 
  <HintPath>\bin\Oracle.DataAccess.dll</HintPath>
</Reference>

As specified in Microsoft’s documentation, publicKeyToken field is optional. However, it is recommended to use it for a strong mapping of your assemblies.

Before going further; What is the public key token? A good description:

The public key token is a small number which is a convenient “token” representing a public key. Public keys are quite long; the purpose of the public key token is to let you refer to keys without saying the whole key.

The question comes up at this point: How to find out this value?

Find public key token value of an assembly file

The easiest way of finding out this value is that using Strong Name Tool. It is used for assembly signing, key management, signature generation and verification. Strong Name Tool is automatically installed with Visual Studio.

Follow the steps below to get values from your assembly file:

  1. Open Visual Studio Command Prompt (Start > Visual Studio > Visual Studio Tools > Developer Command Prompt)
  2. Run the command below. It will display both public key token and public key. Make sure to replace C:\Temp\Oracle.DataAccess.dll with the full path of your DLL file
sn -Tp C:\Temp\Oracle.DataAccess.dll

Assembly public key token

If you only want to see the public key token, you can only use -T parameter.

sn -T C:\Temp\Oracle.DataAccess.dll

Even if you configure everything correctly, you may run into “Could not load file or assembly” issue. Read about Assembly Binding Logging to troubleshoot these kind of issues.

Alternative Way (PowerShell)

If you don’t have Visual Studio installed, you can display the same information by using a PowerShell command. Follow the steps below to to view this information.

  1. Open PowerShell (Start > Search > PowerShell)
  2. Run the command below. Make sure to replace C:\Temp\Oracle.DataAccess.dll with the full path of your DLL file
([system.reflection.assembly]::loadfile("C:\Temp\Oracle.DataAccess.dll")).FullName

DLL public key token powershell

Reference:

Ned Sahin

Blogger for 20 years. Former Microsoft Engineer. Author of six books. I love creating helpful content and sharing with the world. Reach me out for any questions or feedback.

2 thoughts on “How to find out the Public Key Token for an assembly (DLL) file?”

Leave a Comment