Outlook crashes while running through folders?

Add-in Express™ Support Service
That's what is more important than anything else

Outlook crashes while running through folders?
 
BerndH




Posts: 99
Joined: 2014-09-23
Hi,
don?t know if it?s an ad-in-express-problem, but:

I wrote an add-in for outlook. Works well, but on ONE system. Outlook crashes while starting.
My log shows me, it?s while I add a function to the outlook folders.

I have a foreach-loop checking every folder from outlook (recursively) if it?s the "one", then I add a special event.

In my startup-method I do like this:


...
var ns = OutlookApp.GetNamespace("MAPI");
foreach (Outlook.MAPIFolder therootfolder in ns.Folders)
{
    AddFolderHandlers(therootfolder, checkfoldername);
}
...


And in the AddFolderHandlers I do something like this:

             
...
foreach (Outlook.MAPIFolder folder in therootfolder.Folders)
{
    // not my special folder
    if (!folder.FolderPath.ToLower().Equals(checkfoldername)) continue;

    // yes, my folder, add the function
    _outlookFolderWithAddInEvent.Add(folder.Items);
    _outlookFolderWithAddInEvent.Last().ItemAdd += item =>
    {
        var result = TheNewMailitemEvent(item); // my new event for this mail item
            
    };

    // recursive next try with act folder for getting the subfolders
    AddFolderHandlers(folder, checkfoldername);
}


Only on one system I get sometimes an exception like this: "Can?t establish connection with Microsoft Exchange".
Can you give me a hint, what?s my problem here?
Sometimes Outlook just crashes.

Bernd
Posted 24 Apr, 2019 03:11:01 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Bernd,

Thank you for the detailed description and code samples. I may assume that the issue is caused by non released COM objects. Please have a look at the following blog posts, apply the rules described there to your code and re-test it on the affected machine:
https://www.add-in-express.com/creating-addins-blog/2008/10/30/releasing-office-objects-net/
https://www.add-in-express.com/creating-addins-blog/2013/11/05/release-excel-com-objects/

If the issue persists, please let me know what exactly code line throws the "Can't establish connection with Microsoft Exchange" exception.
Posted 24 Apr, 2019 05:18:20 Top
BerndH




Posts: 99
Joined: 2014-09-23
So I did some tests. The client has 4120 folders in its outlook. And the exchange server has as a maximum of 32 MoMT objects per session.

I try to do a workaround not "downloading" all folders for get the ones where I want to install my own special event ....
Posted 24 Apr, 2019 09:09:56 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Bernd,

Thank you for keeping us informed.
Nevertheless, I would recommend that you release COM objects in your code.
Posted 24 Apr, 2019 10:12:05 Top