dik
Posts: 11
Joined: 2012-08-29
|
Dear Add-In Express Team,
I hope you are all healthy...
In my Addin, when i open a .msg file twice, i get following error:
We can't open 'c:\...\test.msg'. It's possible the file is already open, or you don't have permission to open it. To check your permissions, right-click the file folder, then click Properties.
I have located the error in the OutlookExplorerSelectItem_InspectorClose event.
Therefore i broke down my code to this:
Outlook.Inspector currentInspector = (Outlook.Inspector)inspector;
if (OutlookApp.ActiveInspector() != null)
{
Marshal.ReleaseComObject(OutlookApp.ActiveInspector());
}
if (currentInspector.CurrentItem != null)
{
Marshal.ReleaseComObject(currentInspector.CurrentItem);
}
if (currentInspector != null)
{
Marshal.ReleaseComObject(currentInspector);
}
if (inspector != null)
{
Marshal.ReleaseComObject(inspector);
}
}
If i delete following line, everything is fine:
Outlook.Inspector currentInspector = (Outlook.Inspector)inspector;
I know, i am doing something wrong with releasing the COM-objects, but i don?t get it...
Can you support me on this? |
|
Andrei Smolin
Add-in Express team
Posts: 18819
Joined: 2006-05-11
|
Hello dik,
dik writes:
if (OutlookApp.ActiveInspector() != null)
{
Marshal.ReleaseComObject(OutlookApp.ActiveInspector());
}
if (currentInspector.CurrentItem != null)
{
Marshal.ReleaseComObject(currentInspector.CurrentItem);
}
These lines cause the issue because *every* call to a property/method returning a COM object creates a new COM object. There are four such calls above while there are only two Marshal.ReleaseComObject calls.
Andrei Smolin
Add-in Express Team Leader |
|
dik
Posts: 11
Joined: 2012-08-29
|
Hi Andrei,
thank you, now it works. |
|