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 =
AssemblyName.GetAssemblyName(
"C:\\Windows\\assembly\\GAC\\System.Xml\\1.0.5000.0__b77a5c561934e089\\system.xml.dll");
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
Anonymous
August 24, 2006
You can also do it by reflecting on the type instead of knowing the path to the assembly.
typeof(SomeType).Assembly.GetName().GetPublicKeyToken()
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.Anonymous
September 14, 2006
Thanks, Colin. I did not know about this method. Much easier and more portable. Way to go.
John.Anonymous
November 26, 2007
PingBack from http://feeds.maxblog.eu/item_843977.htmlAnonymous
June 09, 2009
PingBack from http://insomniacuresite.info/story.php?id=10401