垂头丧气无法正常工作

垂头丧气无法正常工作

本文介绍了垂头丧气无法正常工作.我做错了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从程序集中加载类并尝试实例化和实例.

这就是我所拥有的

I am loading a class from an assembly and trying to instantiate and instance.

Here''s what I have

public interface IActivity


public abstract class BaseActivity:IActivity


public class MyActivity:BaseActivity //I don't really call stuff MyXxx


并加载它:


And to load it:

Type type = validIActivityTypes.Single(); //I've already performed my checks for this
ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
if (constructor == null)
   return result;
IActivity activity = (IActivity)constructor.Invoke(null);



此时,类型"是"MyActivity",但是...

动臂:



At this point, the ''type'' is ''MyActivity'' but...

Boom:

报价:

ServerControls.dll中发生类型为"System.InvalidCastException"的第一次机会异常.

附加信息:无法将类型为"WorkFlowEngine.Activities.MyActivity"的对象转换为类型为"WorkFlowEngine.Interfaces.IActivity".

A first chance exception of type ''System.InvalidCastException'' occurred in ServerControls.dll

Additional information: Unable to cast object of type ''WorkFlowEngine.Activities.MyActivity'' to type ''WorkFlowEngine.Interfaces.IActivity''.



我做错了什么?

谢谢

刚刚测试type.GetInterfaces():



What am I doing wrong?

Thanks

Just tested type.GetInterfaces():

推荐答案


这篇关于垂头丧气无法正常工作.我做错了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 15:47