Binding for Office automation

M

Max

I am using late binding to automate my code to Microsoft Outlook and I'm getting an error in my code:

Code:
Type objClassType = Type.GetTypeFromProgID("Outlook.Application");
objApp_Late = Activator.CreateInstance(objClassType);

objInspectors_Late = objApp_Late.GetType().InvokeMember("Inspectors", BindingFlags.InvokeMethod, null, objApp_Late, null);
e_InspectorNewEvent_Late = objInspectors_Late.GetType().GetEvent("NewInspector");

At this point e_InspectorNewEvent_Late is null. Can someone tell me why the last line of code does not return an EventInfo?
 
N

Nicholas Paldino [.NET/C# MVP]

Max,

Inspectors is not a method. Rather, it is a property that returns a
collection. That being the case, you should get the property info for the
property, and then call GetValue.

Hope this helps.
 
W

Willy Denoyette [MVP]

Max said:
I am using late binding to automate my code to Microsoft Outlook and I'm
getting an error in my code:

Code:
Type objClassType = Type.GetTypeFromProgID("Outlook.Application");
objApp_Late = Activator.CreateInstance(objClassType);

objInspectors_Late = objApp_Late.GetType().InvokeMember("Inspectors",
BindingFlags.InvokeMethod, null, objApp_Late, null);
e_InspectorNewEvent_Late =
objInspectors_Late.GetType().GetEvent("NewInspector");

At this point e_InspectorNewEvent_Late is null. Can someone tell me why
the last line of code does not return an EventInfo?

This is simply not possible using late binding.
COM objects that enter the CLR that don't support IProvideClassInfo or do
not have any interop assembly registered will be wrapped in a generic type
'System.__ComObject'. That means that
objInspectors_Late.GetType().GetEvent("NewInspector");
will return null as objInspectors_Late, which is of type __ComObject, does
not "expose" the 'NewInspector' event.

Willy.
 

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

Similar Threads

Using COM EXE in C# 3
Kill Process 3
void () type to object 2
CreateDelegate error 7
What am I doing wrong? 7
Checking existance of method in COM object 2
Word Automation 4
Late Binding to a Imported Interface 1

Top