2011-10-27 17 views
0

我得到了下面的代碼創建一個DLL:GetTypes從DLL?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 

namespace Plugin 
{ 

    public class QtObject : DependencyObject 
    { 
     [...] 
    } 

    public class Timer : DependencyObject 
    { 
     [...] 
    } 
} 

我把DLL,想用這個代碼對其進行自省:

var library = Assembly.LoadFrom(libraryPath); 
IEnumerable<Type> types = library.GetTypes(); 

而且在第二行,我有以下錯誤: 「無法加載一個或多個請求的類型。檢索LoaderExceptions屬性以獲取更多信息。」

據我所知,我應該在我的集合中獲得2個「對象」,對應於我的類沒有?

非常感謝您的幫助。

+1

什麼是'LoaderExpection'財產說呢? –

回答

2

也許你的dll的一些引用沒有被讀取dll的應用程序引用。

+0

缺少參考是:( 感謝「Uwe Keim」錯誤告訴我哪一個! –

0

怎麼做這個.....

Assembly SampleAssembly; 
    SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll"); 
    MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("Method1"); 
// Obtain a reference to the parameters collection of the MethodInfo instance. 
ParameterInfo[] Params = Method.GetParameters(); 
// Display information about method parameters. 
// Param = sParam1 
// Type = System.String 
// Position = 0 
// Optional=False 
foreach (ParameterInfo Param in Params) 
{ 
    Console.WriteLine("Param=" + Param.Name.ToString()); 
    Console.WriteLine(" Type=" + Param.ParameterType.ToString()); 
    Console.WriteLine(" Position=" + Param.Position.ToString()); 
    Console.WriteLine(" Optional=" + Param.IsOptional.ToString()); 
} 

請通過這個鏈接for more info