Connecting Tech Pros Worldwide Forums | Help | Site Map

new MAPI.Session() does not work!?!?!?

Gerry
Guest
 
Posts: n/a
#1: Nov 15 '05
I am writing a program in C# which accesses data from Exchange. Code
snippets have been copied from a VB-program.

The VB-program does the following:

'create session and logon
objSession = CreateObject("MAPI.Session")

After this, everyhing works fine.

In c# this looks like:

'create session and logon
objSession = new MAPI.Session();

And this does not work!?!? I get an error stating that Outlook is not
the default client or that the mail client cannot fullfil the
messaging request. Then i also get an exception: ClassFactory cannot
supply requested class.

Can anyone help me on this one? Everything concentrates on the
creation of the session object. In VB.NET it works, in C# not?
Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Nov 15 '05

re: new MAPI.Session() does not work!?!?!?


Gerry,

I forgot to mention, the reason it doesn't work is that MAPI.Session
(when imported) is the name of an interface, not a class. VB6 obfuscated
classes and interfaces (quite poorly I might add). You can create an
instance of MAPI.SessionClass and it should work.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Gerry" <gerry.van.den.broek@logicacmg.com> wrote in message
news:49f5b133.0310280338.70cbd10b@posting.google.c om...[color=blue]
> I am writing a program in C# which accesses data from Exchange. Code
> snippets have been copied from a VB-program.
>
> The VB-program does the following:
>
> 'create session and logon
> objSession = CreateObject("MAPI.Session")
>
> After this, everyhing works fine.
>
> In c# this looks like:
>
> 'create session and logon
> objSession = new MAPI.Session();
>
> And this does not work!?!? I get an error stating that Outlook is not
> the default client or that the mail client cannot fullfil the
> messaging request. Then i also get an exception: ClassFactory cannot
> supply requested class.
>
> Can anyone help me on this one? Everything concentrates on the
> creation of the session object. In VB.NET it works, in C# not?[/color]


Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#3: Nov 15 '05

re: new MAPI.Session() does not work!?!?!?


Gerry,

You might want to use CreateObject in C# as well, through the
Microsoft.VisualBasic library. You could set a reference to
Microsoft.VisualBasic and then access the static CreateObject method through
the Interaction class in the Microsoft.VisualBasic namespace. This should
give you the same results.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Gerry" <gerry.van.den.broek@logicacmg.com> wrote in message
news:49f5b133.0310280338.70cbd10b@posting.google.c om...[color=blue]
> I am writing a program in C# which accesses data from Exchange. Code
> snippets have been copied from a VB-program.
>
> The VB-program does the following:
>
> 'create session and logon
> objSession = CreateObject("MAPI.Session")
>
> After this, everyhing works fine.
>
> In c# this looks like:
>
> 'create session and logon
> objSession = new MAPI.Session();
>
> And this does not work!?!? I get an error stating that Outlook is not
> the default client or that the mail client cannot fullfil the
> messaging request. Then i also get an exception: ClassFactory cannot
> supply requested class.
>
> Can anyone help me on this one? Everything concentrates on the
> creation of the session object. In VB.NET it works, in C# not?[/color]


Closed Thread