我想從一個dll找到公共用戶定義的函數時publickeytoken == null
使用C#公鑰時如何獲得公衆的方法從DLL的== 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它retruns 0字節
byte[] b = Assembly.GetExecutingAssembly().GetName().GetPublicKeyToken();
什麼是你的例外?此外,LoadWithPartialName已過時,您應該使用Load來代替。 – ryadavilli
爲什麼不直接使用組件對象「ass」?既然你剛剛從DLL加載它? – bashmohandes
好吧告訴我一個解決方案,找到公共方法從Dll – Aravind