Binding for Office automation

  • Thread starter Thread starter Max
  • Start date Start date
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?
 
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.
 
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.
 
Back
Top