C# 从DLL获取类型?

C# 从DLL获取类型?,c#,dll,C#,Dll,我获得了创建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 : Dependen

我获得了创建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();
var-library=Assembly.LoadFrom(libraryPath);
IEnumerable types=library.GetTypes();
在第二行,我得到了以下错误: “无法加载一个或多个请求的类型。有关详细信息,请检索LoaderExceptions属性。”

据我所知,我应该在我的集合中得到2个“对象”,对应于我的类


非常感谢您的帮助。

读取dll的应用程序可能没有引用dll的某些引用。

这样做怎么样

  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());
}

请浏览此链接

LoaderExpection属性说明了什么?缺少参考是:(感谢“Uwe-Keim”错误告诉了我是哪一个!