GetSharedDefaultFolder

  • Thread starter Thread starter markus.kraemer
  • Start date Start date
M

markus.kraemer

Hi,

when I use GetSharedDefaultFolder() with Exchange-Users "User1" within
a
C# COMAddin, Outlook doesn't shutdown properly. If the user "User2" is
resolved, everthing works fine.

I have no idea anymore. Any help is welcome.

Thanks,
Markus

The Code is:
======================================================================
Outlook.ApplicationClass oOutlook = new ApplicationClass();
Outlook.NameSpace oNS = oOutlook.GetNamespace("MAPI");
Recipient oRep=oNS.CreateRecipient("User1");
oRep.Resolve();
MAPIFolder oFolder =
oNS.GetSharedDefaultFolder(oRep,olDefaultFolders.olFolderCalendar);
Marshal.ReleaseComObject(oOutlook);
oOutlook=null;
Marshal.ReleaseComObject(oNS);
oNS=null;
Marshal.ReleaseComObject(oRep);
oRep=null;
Marshal.ReleaseComObject(oFolder);
oFolder=null;
 
Test for .Resolved = True before you attempt to do what you are doing, and
make sure to handle any errors. That's critical in any Outlook COM addin. If
you do that you should get rid of your problem.
 
thank you for your response, but the problem still remains. I haved
wrapped the
code within a try-catch-clause. There are no exceptions fired. In both
cases the username
is resolved correctly and the COMAddin has permission to access the
folder, but
after accessing the calendar-folder of "user1" outlook stays in memory
after shutdown.

Markus
 
If Outlook is staying in memory then you aren't releasing all your Outlook
objects when the last Explorer closes (and there are no Inspectors) or when
your code terminates. In addition to releasing all your objects by setting
them to Nothing you should call to release all marshalled COM objects and
call the garbage collector explicitly.
 
Ken,

I guess I'am doing so. OnDisconnection I call

GC.Collect();
GC.WaitForPendingFinalizers();

Is this right? Is there a way to release forgotten references (but I
thing there aren't any)?
I thought I may produce hidden references, but in the code above
everthing seems to be all right.

Thanks,
Markus
 
Are you calling Marshall.ReleaseCOMObject or whatever that method is? Are
you maintaining any collections of objects or handles to objects that would
keep them alive? Are you releasing all objects by setting them to Nothing?
 
Just to avoid any side effects I but the code in a separate executable
and disable any COMAddIns for outlook.

The code just retrieve the calender-folder of an User an terminate.
The method DisposeObject.Singe use Marshal.ReleaseComObject(o) and set
the reference to null. As I can see so far, everythink in the code
should be allright.

Calling the GetSharedFolder() with User "User1" works fine, calling
the function with "User2" cause outlook to stay in memory.

I have still no idea, what's wrong.

Markus

=====================================================
private static void GetSharedFolder(string cUser)
{
Debug.WriteLine("GetSharedFolder");
try
{
Outlook.ApplicationClass oOutlook = new ApplicationClass();
Outlook.NameSpace oNS = oOutlook.GetNamespace("MAPI");
Recipient oRep=null;
MAPIFolder oFolder=null;
oRep = oNS.CreateRecipient(cUser);
if (oRep != null && oRep.Resolve())
{
oFolder = oNS.GetSharedDefaultFolder(oRep,


OlDefaultFolders.olFolderCalendar);
Debug.WriteLine(oRep.Name + " " + oFolder.Name);
}
DisposeObject.Single(oFolder);
DisposeObject.Single(oRep);
DisposeObject.Single(oNS);
DisposeObject.Single(oOutlook);
}
catch (SystemException e)
{
Debug.WriteLine(e.Message);
}
GC.Collect();
GC.WaitForPendingFinalizers();

}

public class DisposeObject
{
public static void Single(object o)
{
if (o != null)
{
int iRefCount = Marshal.ReleaseComObject(o);
o = null;
}
}
}
 
And there are no errors anywhere when you try to get user2? You have the
same permissions on user2 as on user1? If so then I'm stumped.
 
unfortunately there are no erros at all. Maybe there is something wrong
with permissions, but I have read/write access to the calendar of
"user2" via Outlook directly (and the same permission then "user1").

I have tested the code on a second machine where outlook 2003 is
installed. The code works fine for both users (the first test takes
place on a machine with outlook 2000 sp3).

Then I wrapped the code in a separate AppDomain (which should release
all RCW as shown in
http://msdn.microsoft.com/office/ar...3_bk/html/officeinteroperabilitych2_part2.asp
"AppDomain Unloading") -> also without any success on the outlook 2000
machine.

Finally I detele the mailbox of "user2" and create a new one.
Now the same code works also on the outlook 2000 machine.

So, maybe the problem is not due to the code but caused by a "corrupt"
mailbox.
Are there any exchange tools to "repair" a exchange-mailbox (or
perhaps any permission-problems)?

Ken, thanks for your tips so far

Markus
 
Back
Top