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

  • Thread starter Thread starter Gerry
  • Start date Start date
G

Gerry

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?
 
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.
 
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.
 
Back
Top