在我的代码中,我有一个接口 - 可以说它叫做InterfaceName
,它的实现叫做InterfaceImpl
。现在,当我尝试动态地使用下面的代码来获得InterfaceImpl
:无法投射System.Runtime.Remoting.ObjectHandle
object obj = Activator.CreateInstance("ProjectName","ProjectName.Folder.InterfaceImpl");
InterfaceName in = (InterfaceName)obj; //Error pops up here
我收到以下错误
Unable to cast object of type 'System.Runtime.Remoting.ObjectHandle' to type 'ProjectName.Folder.InterfaceName'.
上可能什么错什么建议?
使用Unwrap()方法。 –