0

我想从 dll 中找到公共用户定义函数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);
        }
    }
}

如何解决这个问题

即使我试过这个来查找 publictokenkey 它会重新运行 0 个字节

           byte[] b = Assembly.GetExecutingAssembly().GetName().GetPublicKeyToken();
4

1 回答 1

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);
        }
    }
}
于 2013-01-04T10:09:49.013 回答