Casting Error with Reflection

Posted by Mitchel Sellers on Stack Overflow See other posts from Stack Overflow or by Mitchel Sellers
Published on 2010-04-13T21:14:53Z Indexed on 2010/04/13 21:23 UTC
Read the original article Hit count: 375

Filed under:
|
|

I have an application that uses plugins that are managed via an interface I then dynamically load the plugin classes and cast them to the interface to work with them.

I have the following line of code, assume that IPlugin is my interface.

IPlugin _plugin = (IPlugin)Activator.CreateInstance(oInfo.Assembly, oInfo.FullyQualifiedName)

This should be pretty simple, create the instance and cast it to the interface. I know that the assembly and fully qualified name values are correct, but I am getting the following exception.

Exception= System.InvalidCastException: Unable to cast object of type ‘System.Runtime.Remoting.ObjectHandle’ to type ‘MyNamespace.Components.Integration.IPlugin’. at MyNamespace.Components.Integration.PluginProxy..ctor(Int32 instanceId)

Any ideas what could cause this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection