I'm posting here because there's not a newsgroup about reflection and my
issue is about a COM application: Outlook 2003.
I'm using the following code (I'm referring Outlook and using Reflection in
VS2003):
Type otype = Type.GetTypeFromProgID("Outlook.Application",true);
object outlook = Activator.CreateInstance(otype);
object ns =
otype.InvokeMember("GetNamespace",BindingFlags.InvokeMethod,null,outlook,new
object[]{"MAPI"});
object df =
otype.InvokeMember("GetDefaultFolder",BindingFlags.InvokeMethod,null,ns,new
object[]{Outlook.OlDefaultFolders.olFolderContacts});
The last statement fails, and the exception message is:"Object does not
match target type."
Can anyone help me? What's wrong?
TIA
Pino
Phil Wilson - 17 Dec 2004 15:18 GMT
Doesn't GetDefaultFolder belong to the namespace interface? You're still
using otype.

Signature
Phil Wilson
[Microsoft MVP-Windows Installer]
> I'm posting here because there's not a newsgroup about reflection and my
> issue is about a COM application: Outlook 2003.
[quoted text clipped - 17 lines]
> TIA
> Pino
Pino - 22 Dec 2004 17:07 GMT
Yes, it's true, InvokeMember is called above otype.
I referred Namespace in the 4th parameter of InvokeMember (see: ns)
Haven't I to call InvokeMember on the type of the COM object? I think yes.
Pino
> Doesn't GetDefaultFolder belong to the namespace interface? You're still
> using otype.
[quoted text clipped - 19 lines]
>> TIA
>> Pino