[Mono-list] Casting and Plugin Issue

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


Hello Pablo,

(inline)

El dom, 27-06-2004 a las 17:43, Pablo Fischer escribi=F3:
> Hi!
>=20
> I'll explain what I'm doing and what I'm looking for:
>=20
> 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.
>=20
> So, the method to retrieve a list of posts should return a PostStruct.=20
>=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:
>=20
> 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
>=20
> Will return a PostStruct (cause I'm asking for Posts) with the last 3
> posts (3, and the userInfo).
>=20
> 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:
>=20
> Unhandled Exception: System.InvalidCastException: Cannot cast from
> source type to destination type.
> in <0x0020e> PluginLoader:Main (string[])
>=20
> From:
>=20
> PostStruct p =3D (PostStruct)retVal;
>=20
> 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
"exe".

>=20
> Any Clues?
>=20
> I'm running Beta3
>=20

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.

>=20
> Thanks!
> Pablo

Hope this helps,

Rodolfo