Can?t open Outlook .msg files twice

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

Can?t open Outlook .msg files twice
 
dik




Posts: 11
Joined: 2012-08-29
Hi,

i had read several posts about this problem and i know, that the main reason is a unreleased COM object.

My code runs into a standalone application and i use Office 2016 32x.

Here?s my code:


                                                else if (Enum.IsDefined(typeof(Enumerations.Office.Outlook), fileExtension))
                                                {
                                                    Outlook.Application OutlookApp = null;
                                                    Outlook.MailItem mailItem = null;
                                                    Outlook.Inspector inspector = null;

                                                    try
                                                    {
                                                        OutlookApp = GetOutlookApplication();

                                                        if (OutlookApp == null)
                                                        {
                                                            OutlookApp = new Microsoft.Office.Interop.Outlook.Application();
                                                        }

                                                        mailItem = OutlookApp.Session.OpenSharedItem(m_FileInfo.FullName) as Microsoft.Office.Interop.Outlook.MailItem;
                                                        inspector = mailItem.GetInspector;

                                                        ((InspectorEvents_10_Event)inspector).Close += CloseMailEventHandler;

                                                        mailItem.Display();
                                                        
                                                    }
                                                    catch (Exception ex)
                                                    {


                                                    }
                                                    finally
                                                    {
                                                       if(OutlookApp != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(OutlookApp);
                                                       if(mailItem != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(mailItem);
                                                       if(inspector != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(inspector);
                                                    }
                                                }


Can you please assist me, i dont?t get the error
Posted 26 Nov, 2019 04:44:19 Top
dik




Posts: 11
Joined: 2012-08-29
Posted 26 Nov, 2019 04:53:41 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Dik,

First of, check whether the issue persists if you turn all COM add-ins off.

Then, try to release the COM object returned by OutlookApp.Session. Finally, try to disconnect inspector from the Close event.


Andrei Smolin
Add-in Express Team Leader
Posted 26 Nov, 2019 04:59:27 Top
dik




Posts: 11
Joined: 2012-08-29
Hello Andrej,

thank you for the fast reply!

I turned off all COM Addins and now it works fine...
After that i tested allthese COM-Addins and the error came from an another COM-Addin i created in the past...

I think there were an unreleased COM-object....

Thank you for the support and have a nice day
Posted 26 Nov, 2019 05:15:07 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 26 Nov, 2019 07:42:24 Top