Using late binding if depending on multiple versions of Outlook

Managed Outlook add-ins that use the Outlook Primary Interop Assembly (PIA) are compiled with type information that the PIA provides. This early binding of type information for methods and properties allows the compiler to perform type and syntax checks to ensure that the correct number and type of parameters are passed to the method or property, and that the returned value is of the expected type.

However, early binding has the disadvantage of introducing version incompatibility if a method or property that the add-in calls has a different declaration in an earlier version. For example, adding new methods and properties or modifying existing members of an object can alter the binary layout of the object and cause problems with a managed add-in that uses the more recent type information to automate an earlier version of Outlook.

In such cases, late binding waits until run time to bind property and method calls to their objects. Late binding can help avoid complications from types that are different in different versions of Outlook, and is especially useful when writing add-ins that depend on multiple versions of Outlook.

Late binding involves an add-in calling the IDispatch interface implemented by Outlook. To use late binding in Visual C#, use the System.Type.InvokeMember method. This method calls IDispatch::GetIDsOfNames and IDispatch::Invoke to bind to Outlook’s methods and properties. The IDispatch::GetIDsOfNames method allows Visual C# to interrogate an object about what methods and properties it supports and the IDispatch::Invoke method then allows Visual C# to call those methods and properties.

See also