1
votes

The returned type of namespaceObjType is a System.__ComObject and it's impossible to call InvokeMember("OpenSharedItem", ...) on it. How do you need to call this method with the late binding technique? The only difference I see is that the returned object type of the Session property is only an interface instead of a real COM Class.

Code example:

object outlookApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
Type outlookAppType = outlookApp.GetType();
object templateObj = null;
System.IO.File.Copy(templateName, temporaryFileName, true);
object namespaceObj = outlookAppType.InvokeMember("Session", System.Reflection.BindingFlags.GetProperty, null, outlookApp, new object[0]);
if(namespaceObj != null)
{
  Type namespaceObjType = namespaceObj.GetType();
  // Exception on the next line of code
  templateObj = namespaceObjType.InvokeMember("OpenSharedItem", System.Reflection.BindingFlags.InvokeMethod, null, outlookApp, new object[] { temporaryFileName });
}

Exception after executing is: Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))

1

1 Answers

0
votes

You need to pass a namesapce object instead of the outlookApp:

namespaceObjType.InvokeMember("OpenSharedObject", System.Reflection.BindingFlags.InvokeMethod, null, namespaceObj, new object[] { temporaryFileName });

Anyway, the Namespace class doesn't provide the OpenSharedObject moded.

Are you interested in the OpenSharedItem method?