CDO in .NET-Service: COM-Objects crashing

C

Corinna John

We have an .NET service (written in C#, running in the
LocalService account), which impersonates an account,
opens a CDO session and then reads/writes mails and tasks
from/to folders only accessible by the impersonated user.

If the service calls windowsImpersonationContext.Undo()
after the CDO session has logged on, it usually can read
public folders and their content without a problem. But
every once in a while (average after 20 objects have been
read), it throws a System.NullReferenceException at
System.Runtime.InvokeDispMethod.

If the service does not undo the impersonation and runs in
the account which is logged on to Exchange, the
NullPointerException is thrown exactly when the fourth CDO
object is retrieved. I have already tried opening a new
session before opening a folder, but then the Exception is
thrown while logging on the fourth session.

If the fourth action is reading the contents of a folder,
the NullreferenceException occurs in
MAPI.Folder.get_Messages().
If I try to read a message, it occurs in
MAPI.Message.get_Text(), MAPI.Message.get_Attachments() or
another get-method.

Here is a typical stack trace for reading message
properties:

System.NullReferenceException: Der Objektverweis wurde
nicht auf eine Objektinstanz festgelegt.
at System.RuntimeType.InvokeDispMethod(String name,
BindingFlags invokeAttr, Object target, Object[] args,
Boolean[] byrefModifiers, Int32 culture, String[]
namedParameters)
at System.RuntimeType.InvokeMember(String name,
BindingFlags invokeAttr, Binder binder, Object target,
Object[] args, ParameterModifier[] modifiers, CultureInfo
culture, String[] namedParameters)
at System.RuntimeType.ForwardCallToInvokeMember(String
memberName, BindingFlags flags, Object target, Int32[]
aWrapperTypes, MessageData& msgData)
at MAPI.Message.get_Attachments()
at Vita.Bk.SecureItem.CopyFrom(Message message)

And here is a typical stack trace for listing folder items:

System.NullReferenceException: Der Objektverweis wurde
nicht auf eine Objektinstanz festgelegt.
at System.RuntimeType.InvokeDispMethod(String name,
BindingFlags invokeAttr, Object target, Object[] args,
Boolean[] byrefModifiers, Int32 culture, String[]
namedParameters)
at System.RuntimeType.InvokeMember(String name,
BindingFlags invokeAttr, Binder binder, Object target,
Object[] args, ParameterModifier[] modifiers, CultureInfo
culture, String[] namedParameters)
at System.RuntimeType.ForwardCallToInvokeMember(String
memberName, BindingFlags flags, Object target, Int32[]
aWrapperTypes, MessageData& msgData)
at MAPI.Folder.get_Messages()
at
Vita.Bk.OutlookService.OutlookService.ListUserTodoItems
(Object[] parameters) in c:\visual studio-projekte\mba
kataster\outlookservice\outlookservice.cs:line 529

That is how the service behaves on .Net Framework 1.0
without service packs. I have installed Service Pack 2,
now the NullReferenceExceptions always occur at random, no
matter if the service is still impersonating a user or not.
The "Outlook EMail Security" stuff has been configured to
allow all MAPI and CDO actions, but there is still no
change,
the CDO objects are throwing Exceptions after a while.

Does anyone know what happens here? Is is a problem of CDO
or .NET Interop?

Thank in advance,
corinna
 
G

Guest

I found a reason/solution now:

CDO checks the RPC quality. If the connection fails for a
second (what happens every now and then, whenever the
network slows down), it cannot be re-established.

I solved the problem by writing another service. When the
client application notices an exception in the exchange
access service or an unexpected response, it sends a
request to the restarting-service to restart the first
service. Now it runs alright, except the delays while the
exchange access service is being restarted.

But I still don't know why the RPC connection is quite
stable with the wrong logon, and fails regularly with the
correct logon :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top