Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Passing an interface pointer through MethodInfo.Invoke

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Lutz - 08 Nov 2006 22:53 GMT
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?
Shailen Sukul - 09 Nov 2006 01:14 GMT
http://www.mztools.com/articles/2006/MZ013.htm
http://support.microsoft.com/?kbid=320523

> 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
[quoted text clipped - 28 lines]
>
> How do I get the types to match?
John Lutz - 09 Nov 2006 14:12 GMT
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.

> http://www.mztools.com/articles/2006/MZ013.htm
> http://support.microsoft.com/?kbid=320523
[quoted text clipped - 31 lines]
> >
> > How do I get the types to match?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.