Passing an interface pointer through MethodInfo.Invoke

G

Guest

Our app is mainly COM based. We allow .NET plug-ins. When a plug-in is
installed, it receives a COM pointer to the app. The plug-in implements our
IExtensionImpl interface and gets the app pointer through the OnCreate
method...

public void OnCreate(IApplication pApp)...

The plug-in that I'm working on also allows sub-plug-ins. These
sub-plug-ins are simple DLLs that provide methods that are accessed via
Reflection.

Here's my problem... I need to forward the IApplication pointer to the
sub-plug-in. Here's the sub-plug-in Create routine...

public void Create(IApplication app)...

The plug-in calls the sub-plug-in using the following Reflection code...

MethodInfo method = Reflect.GetNamedMethod(type, "Create",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Object[] parameters = new Object[1] { m_app }; // m_app was
cached in OnCreate()
Type t1 = parameters[0].GetType();
Type t2 = method.GetParameters()[0].ParameterType;
method.Invoke(testType, parameters);

The Invoke fails with a type mismatch:

t1 = System.__ComObject
t2 = IApplication

How do I get the types to match?
 
G

Guest

Thanks for the information. I tried the following:

Object[] parameters = new Object[1] { m_app as IApplication };

It didn't fix the problem. I still get a type mismatch exception. It
seems like I either need to make my reflected method have a signature like
this...

void Create(System.__ComObject app)

Or else figure out how to make the Object array constructor convert my
interface pointer to something other than System.__ComObject.

I looked at some of the Marshalling routines but I really want to keep
everything in-process.

Shailen Sukul said:
http://www.mztools.com/articles/2006/MZ013.htm
http://support.microsoft.com/?kbid=320523

John Lutz said:
Our app is mainly COM based. We allow .NET plug-ins. When a plug-in is
installed, it receives a COM pointer to the app. The plug-in implements our
IExtensionImpl interface and gets the app pointer through the OnCreate
method...

public void OnCreate(IApplication pApp)...

The plug-in that I'm working on also allows sub-plug-ins. These
sub-plug-ins are simple DLLs that provide methods that are accessed via
Reflection.

Here's my problem... I need to forward the IApplication pointer to the
sub-plug-in. Here's the sub-plug-in Create routine...

public void Create(IApplication app)...

The plug-in calls the sub-plug-in using the following Reflection code...

MethodInfo method = Reflect.GetNamedMethod(type, "Create",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Object[] parameters = new Object[1] { m_app }; // m_app was
cached in OnCreate()
Type t1 = parameters[0].GetType();
Type t2 = method.GetParameters()[0].ParameterType;
method.Invoke(testType, parameters);

The Invoke fails with a type mismatch:

t1 = System.__ComObject
t2 = IApplication

How do I get the types to match?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top