rwheeler23
asked on
Getting the PublicKeyToken using C#
I need to find the PublicKeyToken of an assembly called Application.Dynamics
Here is my method for getting the public key token.
========================== ========== ========== ========== ========== ========== ========== ========== ========== ==========
private static string GetPublicKeyTokenFromAssem bly(Assemb ly assembly)
{
var bytes = assembly.GetName().GetPubl icKeyToken ();
if (bytes == null || bytes.Length == 0)
return "None";
var publicKeyToken = string.Empty;
for (int i = 0; i < bytes.GetLength(0); i++)
publicKeyToken += string.Format("{0:x2}", bytes[i]);
return publicKeyToken;
}
========================== ========== ========== ========== ========== ========== =======
The question is how to I assign this value to a string?
string TokenString = GetPublicKeyTokenFromAssem bly("Appli cation.Dyn amics");
This does not work. I get a message about not being able to convert a string to an assembly reference.
How do structure so I can see the value of the Public Key Token of this assembly?
Here is my method for getting the public key token.
==========================
private static string GetPublicKeyTokenFromAssem
{
var bytes = assembly.GetName().GetPubl
if (bytes == null || bytes.Length == 0)
return "None";
var publicKeyToken = string.Empty;
for (int i = 0; i < bytes.GetLength(0); i++)
publicKeyToken += string.Format("{0:x2}", bytes[i]);
return publicKeyToken;
}
==========================
The question is how to I assign this value to a string?
string TokenString = GetPublicKeyTokenFromAssem
This does not work. I get a message about not being able to convert a string to an assembly reference.
How do structure so I can see the value of the Public Key Token of this assembly?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
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\Fra
Microsoft (R) .NET Framework Strong Name Utility Version 3.5.21022.8
Copyright (c) Microsoft Corporation. All rights reserved.
Public key token is b77a5c561934e089