CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Wednesday, October 11, 2006

Getting Public KeyToken from assembly in .NET

//prints info about assembly, including public key token
System.Reflection.Assembly.LoadFrom
      (@"C:\SomeAssembly.dll").ToString();
// returns only the public key token
public static string GetAssemblyPublicKeyToken
       (Assembly assembly)
{
    string token = "";
    Byte[] pt = assembly.
       GetName().GetPublicKeyToken();
    for (int i = 0; i < pt.Length; i++)
    {
        token += pt[i].ToString("x");
    }
    return token;
}

Post a Comment