【发布时间】:2016-12-17 08:26:14
【问题描述】:
我有一个在运行时加载的 dll。我正在尝试从运行时动态加载的 dll 创建每个类型的实例,并将这些实例添加到列表中。 dll中的所有类都基于AYClass,因此应该成功地将它们添加到List中。但是我遇到了如下错误
Exception thrown:
'Microsoft.CSharp.RuntimeBinder.RuntimeBinderInternalCompilerException' in Microsoft.CSharp.dll
Additional information: An unexpected exception occurred while binding a dynamic operation
我的代码如下...
Assembly assembly = Assembly.LoadFrom(@"D:\Library\CurrencyData.dll");
List<AYClass> listObjects = new List<AYClass>();
foreach (Type type in assembly.GetExportedTypes())
{
if (type.BaseType.ToString().Contains("AYClass"))
{
dynamic c = Activator.CreateInstance(type);
listObjects.Add(c); // ******* Exception is thrown here
}
}
我应该怎么做才能解决这个问题?
【问题讨论】: