I am finding that the methods exposed by an instance of __ComObject don't match what I expect.
Background
Here is an example that works as expected:
var type = Type.GetTypeFromProgID("Excel.Application");
foreach ( var member in type.GetMembers() )
{
Console.WriteLine(m.Name);
}
If you run this, you'll get a list of the properties and methods exposed by Excel.Application, such as
ActivateMicrosoftApp
ActiveCell
ActiveChart
ActiveDialog
ActiveEncryptionSession
//Etc... there are about 100 methods and properties
In addition, you would find that all of these methods can be invoked using InvokeMember:
var instance = Activator.CreateInstance(type, null);
type.InvokeMember
(
name: "Exit",
invokeAttr: BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMember,
binder: null,
target: instance,
args: new [] {}
);
The above will cause Excel to exit, for example.
The problem
Here's the issue. I have a custom COM component (contained in a third party .exe) where the properties and methods do not match what is expected, nor do they match what is shown in Object Browser. Instead, I get back these:
ToString
GetLifetimeService
InitializeLifetimeService
CreateObjRef
Equals
GetHashCode
GetType
These look like the properties and methods that belong to a MarshalByReferenceObject. But that isn't what I need.
In addition, if I attempt to invoke any of the known methods using InvokeMember, I get this error:
Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))`).
The question: What are these methods? Where is my proper ComObject? How do I call the actual methods that belong to the COM component?
Note: If I generate an interop assembly using TlbImp.exe, I get a .NET proxy class that contains all the proper properties and methods, and I can invoke them and they work.
Note also: I used this solution to obtain the type's name (it is correct). Since the code in the example worked, it also demonstrates that the COM component does indeed expose IDispatch.
User contributions licensed under CC BY-SA 3.0