rwheeler23
asked on
How to get PublicKeyToken using C#
Using these two pieces of code how would I get the PublicKeyToken for a dll called Dynamics.Application.dll? How do I pass the name down as an argument?
using System;
using System.Reflection;
namespace EE_Q29126560
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"Object Assembly PublicKeyToken: {GetPublicKeyTokenFromAssembly(Assembly.GetAssembly(typeof(object)))}");
Console.ReadLine();
}
static string GetPublicKeyTokenFromAssembly(Assembly assembly)
{
var bytes = assembly.GetName().GetPublicKeyToken();
if (bytes == null || bytes.Length == 0)
return "None";
var result = string.Empty;
for (int i = 0; i < bytes.GetLength(0); i++)
result += $"{bytes[i]:x2}";
return result;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER