This is how I'm doing it now using the default parameterless constructor:
IPlugin plug =
AppDomain.CreateInstanceFromAndUnwrap(strAssembly, strTypeName) as IPlugin;
plug.SetDispatcher(msgDispatcher);
I have to call SetDispatcher afterwards to inject another object.
I would rather the CreateInstanceFromAndUnwrap(...) call do it all.
I've tried this:
return domain.CreateInstanceFromAndUnwrap(
assemblyName, // assembly name
typeName, // type name
false, // ignore case
BindingFlags.CreateInstance, // binding flags
null, // binder
new object[] { dispatcher }, // args
null, // culture
null, // activationAttributes
null // securityInfo
) as IPlugin;
but it doesn't work.
Any ideas?
I've looked at the MSDN docs but there are no examples of how to use the
last two versions of CreateInstanceFromAndUnWrap.
Regards,
Ian.
> This is how I'm doing it now using the default parameterless constructor:
>
> IPlugin plug =
> AppDomain.CreateInstanceFromAndUnwrap(strAssembly, strTypeName) as IPlugin;
> plug.SetDispatcher(msgDispatcher);
>
> I have to call SetDispatcher afterwards to inject another object.
>
> I would rather the CreateInstanceFromAndUnwrap(...) call do it all.
>
> I've tried this:
>
> return domain.CreateInstanceFromAndUnwrap(
> assemblyName, // assembly name
> typeName, // type name
> false, // ignore case
> BindingFlags.CreateInstance, // binding flags
> null, // binder
> new object[] { dispatcher }, // args
> null, // culture
> null, // activationAttributes
> null // securityInfo
> ) as IPlugin;
>
> but it doesn't work.
>
Ah, that's always a problem. Doesn't work *how*? What are the actual
parameter values? What's the actual exception you get?
The online MSDN doesn't have examples, but the copy that comes with Visual
Studio does. Try BindingFlags.Default rather than
BindingFlags.CreateInstance, and make sure you specify full names for both
the assembly and the type. Also, note that you've specified that the search
should be case-sensitive, so make sure that's exactly right.
--
J.
The concrete implementation of IPlugIn has a default ctor and a non-default
ctor that takes a single argument of type IDispatcher. IDispatcher is my own
interface and not from the .NET Framework. IDispatcher has a single method
with this signature: void EnqueueMessage(string messageText).
When I call the many-argument version of CreateInstanceFromAndUnwrap, a
transparent proxy representing IPlugin is returned, but when I try to call
methods on the returned IPlugin I get an exception. As I'm at home now, I'll
have to post the details of the exception on Monday when I'm back in work.
Thanks.
Ian.
The "extended" CreateInstanceAndUnwrap
It is - just use this ctor:
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_mscorlib/html/62d28d33-bd19-357f-9673-f220b143ece3.htm
Unfortunately that means that you have to supply a lot of arguments, but it
can be done.
--
Regards,
Brian Rasmussen [C# MVP]
http://kodehoved.dk
"IanT8" <Ia...@discussions.microsoft.com> wrote in message
news:58283604-D4A3-4B91...@microsoft.com...
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/