我希望在publickeytoken == null
OpenFileDialog obj = new OpenFileDialog();
if (obj.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Assembly ass = Assembly.LoadFrom(obj.FileName);
// Here its getting Exception because Publickeytoken == null;
Assembly a = Assembly.LoadWithPartialName(ass.FullName);
Type[] types = a.GetTypes();
foreach (Type type in types)
{
if (!type.IsPublic)
{
continue;
}
MemberInfo[] members = type.GetMembers(BindingFlags.Public
| BindingFlags.Instance
| BindingFlags.InvokeMethod);
foreach (MemberInfo member in members)
{
Console.WriteLine(type.Name + "." + member.Name);
}
}
}
如何解决这个问题
即使我尝试查找公共令牌密钥,它返回0字节
byte[] b = Assembly.GetExecutingAssembly().GetName().GetPublicKeyToken();
答案 0 :(得分:1)
您的绑定标记错误,您可以直接使用ass
:
OpenFileDialog obj = new OpenFileDialog();
if (obj.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Assembly ass = Assembly.LoadFrom(obj.FileName);
foreach(var type in ass.GetTypes())
{
MethodInfo[] members = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
foreach (MemberInfo member in members)
{
Console.WriteLine(type.Name + "." + member.Name);
}
}
}