Rainer
Rainer

Reputation: 29

Accessing in C# a method not defined in type library

While creating a plugin for a third party application I hit a problem that the type library provided by the creators of the application does not contain all methods available for the plugins.

Basically everything works if I use VisualBasic and don't have the Option Strict On set. As soon as I set it to "On" I get errors that Late binding is not available with Strict On.

Now I really would like to port this code to C#, but I can't figure out how to get those methods to work.

The plugin system works in the way that my plugin gets an Application object and later I just call: Application.IntermediateObject.InterestingMethod(Variable) - this works fine in VB without "Strict On"

In C# this doesn't even compile as IntermediateObject does not contain a definition of "InterestingMethod" (as I can also see by using the Windows SDK COM Object Browser). My best guess so far was that I should be able to get to it with something like that:

IntermediateObject.GetType().GetMethod("InterestingMethod");

But the result of that is just "null".

Am I doing something wrong here? or is this a dead-end and I must stick to VB?

PS: I have no power to make the application creators fix their type library, so that is not an option.

Upvotes: 2

Views: 103

Answers (1)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174299

You could try to employ the dynamic keyword here:

dynamic tmp = Application.IntermediateObject;
tmp.InterestingMethod(variable);

This might work, although I am not certain as reflection doesn't seem to work.

Upvotes: 4

Related Questions