Assemblies and Public Key Tokens

I'm working on a SharePoint v3 workflow project using the out-of-the-box (OOB) techniques. In order to install the workflow, you need to know the public key token for the signed assembly that you add to the Global Assembly Cache (GAC). To get this, I have been installling the assembly into the GAC and then looking at the token via the .NET config UI. No fun! Tedious...

So, I wrote some code to grab the key token. It pulls it as a byte array, and I can just convert from there. Here's my code to do the job:


public byte[] GetToken()

//Uncomment this and comment the statement below it to get a different take on things.

//Here, I am getting the key token for the executing assembly
//AssemblyName myAssembly = AssemblyName.GetAssemblyName(Assembly.GetExecutingAssembly().Location);

//Here, I am getting the key token for a different assembly in the GAC
AssemblyName myAssembly =
byte[] myKey = myAssembly.GetPublicKeyToken();
return myKey;

Here's the callling code:

Dim c1 As New ClassLibrary1.Class1
Dim b() As Byte
b = c1.GetToken()

 Rock Thought for the Day:

 I was not sleeping well on Monday (just like Sunday, just like Tuesday, Wednesday, and last night), and I listened to KEXP to pass the time. I heard this fantastic song by Sufjan Stevens, "Pittsfield" from his album, Avalanche. Check it out.

Rock On

Comments (5)

  1. Colin Bowern says:

    You can also do it by reflecting on the type instead of knowing the path to the assembly.


    Remember that the GAC was designed to be moved as demonstrated by the existence of GetCachePath in fusion.dll as well as the fact that not everyone uses C:WINDOWS.

  2. Thanks, Colin. I did not know about this method. Much easier and more portable. Way to go.


Skip to main content