[Mono-list] Casting and Plugin Issue

Rodolfo Campero rodolfocampero@hotmail.com
Sun, 27 Jun 2004 20:07:07 -0300

Hello Pablo,


El dom, 27-06-2004 a las 17:43, Pablo Fischer escribi=F3:
> Hi!
> I'll explain what I'm doing and what I'm looking for:
> I've three plugins to post/get data from different Blogs (supporting
> XMLRPC and SOAP). In order to standardize these plugins I'm using
> Interfaces and three type of Structs (PostStruct, BlogStruct,
> CategoryStruct) each one XmlSerialized.
> So, the method to retrieve a list of posts should return a PostStruct.=20
> The problem is: When I'm using the plugin to Invoke the methods of these
> plugins (dll's) I'm having problems with these objects, for example:
> my_method =3D t.GetMethod("MGetPosts");
> object retVal =3D my_method.Invoke(activator,
>                                 BindingFlags.Instance |   =20
> 				BindingFlags.NonPublic |
> 				BindingFlags.InvokeMethod,
>                                 null,
>                                 new Object[]{3, user},
>                                 null);=20
> Will return a PostStruct (cause I'm asking for Posts) with the last 3
> posts (3, and the userInfo).
> When I do a WriteLine of retVal I get a PostStruct, that should be,
> however, When I try to cast retVal to a PostStruct so I can read I get
> this:
> Unhandled Exception: System.InvalidCastException: Cannot cast from
> source type to destination type.
> in <0x0020e> PluginLoader:Main (string[])
> From:
> PostStruct p =3D (PostStruct)retVal;
> What I'm doing wrong if the Console.WriteLine(retVal) show me that
> retVal is a PostStruct?.

Maybe you're compiling the source file where PostStruct is defined in
both assemblies, caller and callee. What you should do is to compile it
only in the caller, and then compile the plugin with a reference to the
caller assembly. Beware that you can't do this if the caller is an

> Any Clues?
> I'm running Beta3

Maybe you could also add an interface, lets say IPlugin, which defines
the method GetPosts. This way you wouldn't have to use reflection in
order to invoke methods.

> Thanks!
> Pablo

Hope this helps,