MAPIFolder.get_Folders and Exchange

  • Thread starter Thread starter mwebb
  • Start date Start date
M

mwebb

Hi all,
My Add-In couldn`t create Folder in Outlook. This error occurs only if
Exchange
caching mode is activated in Outlook and user machine, where the problem
occurs, have large OST file (about 40000 emails).

Using Redemption, VSTO, PIA.

Thanks
 
What version of Outlook? Where are you trying to create a folder? How are
you trying to create the folder? Any errors or exceptions? Any other
information that might be helpful?
 
Sorry, I am using Ol2003.

One of the error:
The operation failed.
Microsoft Office Outlook
at Microsoft.Office.Interop.Outlook.MAPIFolder.get_Folders()
Crashed at:
Globals.ThisApplication.GetNameSpace("MAPI").GetDefaultFolder(olFolderContacts).Folders.Add("FolderName")

another one:
Error in IMsgStore.OpenEntry: MAPI_E_CALL_FAILED
Redemption.RDOExchangeMailboxStore
at Redemption.RDOStoreClass.GetFolderFromID(String EntryID, Object Flags)
Crashed at:
rdoFld = rdoSession.Stores.DefaultStore.GetFolderFromID(sEntryID)
 
Using so many concatenated dot operators isn't a good way to go for a few
reasons. For one thing it makes it impossible to find where something is
failing. Also it creates internal object variables, one for each dot
operator, that may or may not be released in a timely manner (especially in
managed code).

You also should be placing any sort of operation like that where you are
getting COM objects through the Interop in Try...Catch blocks so you don't
have unhandled exceptions. In addins all exceptions must be handled or
Outlook may hang or remain in memory or the addin or Outlook may crash.

So to see what's going on change your code to separate everything in an
exception handling block and step the code to validate where the exception
is being thrown. Also, for managed code I've found it best to use all method
arguments, including optional ones. So the code to test on would look
something like this:

Dim oNS As Outlook.NameSpace = Globals.ThisApplication.GetNameSpace("MAPI")
oNS.Logon
Dim oContacts As Outlook.MAPIFolder = oNS.GetDefaultFolder(olFolderContacts)
Dim colFolders As Outlook.Folders = oContacts.Folders
Dim oNewFolder As Outlook.MAPIFolder = colFolders.Add("FolderName",
olFolderContacts)

See where the code is failing then.

Another thing to consider is if this code is being run in a loop of some
sort is that you might be exceeding the RPC channel limit that by default
limits any client to about 250 RPC channel connections to the Exchange
server. Each object you create opens a channel (another way that
concatenated dot operators are a problem) and the channels might not be
released until the procedure ends or you explicitly release the objects (not
only setting them to Nothing but also calling Marshal.ReleaseComObject and
maybe even GC.Collect).
 
Hi,

I have this errors when my code tried to create 2 folders and 5000 Contacts
in Exchange on one of the clients machine . The problem is that folders were
created, but i can't access the properties (like Folder.Items.Count) of any
folder, even the for folders that i've created. Also, no Contacts were
created, so i'm not sure that it's because of 250 open RPC channel limit.
And my actual code is not using concatenated dot operators. The provided
early code was just an example.
 
And you say the same code works in non-cached mode but not in cached mode
(or vice versa)? Then I'm stumped based on the code snippets I've seen.
 
You might be running out of the 255 open objects limit impose dby Exchange
in the online mode.
In case of OOM, have you tried to
1. Do not use multiple dot notation to make sure you don't get implicit
variables
2. Explicitly release all COM objects that you are done with as soon as you
are done with them using Marshal.ReleaseCOMOBject. Calling GC.Collect()
every once in a while also won't hurt

In case of Redemption, try the latest (4.5) version - it manages MAPI
objects internally and automatically relases the MAPI objects that can be
reopened when the number of open objects gets too high (see the second item
at http://www.dimastr.com/redemption/history.htm)

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Hi, all.
Thanks, i will try v. 4.5 of Redemption

Dmitry Streblechenko said:
You might be running out of the 255 open objects limit impose dby Exchange
in the online mode.
In case of OOM, have you tried to
1. Do not use multiple dot notation to make sure you don't get implicit
variables
2. Explicitly release all COM objects that you are done with as soon as you
are done with them using Marshal.ReleaseCOMOBject. Calling GC.Collect()
every once in a while also won't hurt

In case of Redemption, try the latest (4.5) version - it manages MAPI
objects internally and automatically relases the MAPI objects that can be
reopened when the number of open objects gets too high (see the second item
at http://www.dimastr.com/redemption/history.htm)

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top