Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / July 2005

Tip: Looking for answers? Try searching our database.

GetSharedDefaultFolder

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
markus.kraemer@proacta.de - 19 Jul 2005 14:09 GMT
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;
Ken Slovak - [MVP - Outlook] - 19 Jul 2005 15:44 GMT
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.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Hi,
>
[quoted text clipped - 24 lines]
> Marshal.ReleaseComObject(oFolder);
> oFolder=null;
markus.kraemer@proacta.de - 20 Jul 2005 17:45 GMT
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
Ken Slovak - [MVP - Outlook] - 20 Jul 2005 19:03 GMT
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.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> thank you for your response, but the problem still remains. I haved
> wrapped the
[quoted text clipped - 6 lines]
>
> Markus
markus.kraemer@proacta.de - 20 Jul 2005 19:48 GMT
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
Ken Slovak - [MVP - Outlook] - 21 Jul 2005 14:48 GMT
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?

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Ken,
>
[quoted text clipped - 10 lines]
> Thanks,
> Markus
markus.kraemer@proacta.de - 23 Jul 2005 15:07 GMT
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;
     }
 }
}
Ken Slovak - [MVP - Outlook] - 25 Jul 2005 15:05 GMT
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.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Just to avoid any side effects I but the code in a separate executable
> and disable any COMAddIns for outlook.
[quoted text clipped - 54 lines]
>  }
> }
markus.kraemer@proacta.de - 27 Jul 2005 14:25 GMT
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/archive/default.aspx?pull=/library/en-us/odc_of
2003_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
John  Liu - 29 Jul 2005 04:17 GMT
If you are not aware, ScanPST is good for repairing PST and OST files.
It comes with your Outlook installation and you already have it.

Sue has a better write up here:
http://www.slipstick.com/problems/scanpst.htm

I don't know whether it would have fix your specific problem here
though.

jliu
johnliu.net
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.