我想將一個C#應用程序指向一個DLL並獲取該DLL中定義的類型列表。 我到目前爲止看起來表面上看起來很正確,但給出了下面指出的錯誤。如何從C#中的DLL中獲取類型列表?
using System.Reflection;
...
static void Main(string[] args)
{
Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom("C:\\MyAssembly.dll"); //error happens here
foreach (Type tp in SampleAssembly.GetTypes())
{
Console.WriteLine(tp.Name);
}
}
/*
This will give me:
Unable to load one or more of the requested types.
Retrieve the LoaderExceptions property for more information.
I wish it would give me something like this:
MyClass1
MyClass2
MyClass3
*/
相同的代碼剛剛正常工作對我來說,使用VS2k8任何代碼....請問你的DLL指向(1)肯定存在和(2)是.net程序集?另外,哪行代碼是你收到的錯誤?我懷疑Assembly.LoadFrom行嗎? – Rob 2010-08-19 21:46:32
爲什麼不按照建議,查看異常的LoaderExceptions屬性以獲取更多信息? – Timwi 2010-08-19 21:49:03
@Rob - 是的,它確實存在,它是一個.net程序集。你對這行代碼是正確的 - 它發生在.LoadFrom行上。我編輯了我的問題來說明問題。 – JosephStyons 2010-08-20 16:01:15