.MSG file locked the second time it's opened

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

.MSG file locked the second time it's opened
 
Fabrice




Posts: 158
Joined: 2010-12-13
Hello Andrei,

Customer reached me for the same problem than these topics:
- https://www.add-in-express.com/forum/read.php?FID=5&TID=13947
- https://www.add-in-express.com/forum/read.php?FID=5&TID=13956

I'm using:
- Outlook 2019 (16.0.13901.20366) 32 bit
- ADX 9.4.4644.0

I've reproduced the case in an almost empty add-in, and get to this code:

        private void adxOutlookEvents_InspectorActivate(object sender, object inspector, string folderName)
        {
            var oInspector = inspector as Outlook.Inspector;
            this.ConnectEventsTo(oInspector);
        }

        private void adxOutlookEvents_ExplorerSelectionChange(object sender, object explorer)
        {
            this.ConnectEventsTo(explorer as Outlook.Explorer);
        }


The ConnectEventsTo is a custom code, I'll send you the complete repro project on your email.

If I don't connect event, the file is not locked after mail is closed. If I connect to events the file stay locked after closed. I've more than triple-checked any COM reference and everything should be released.

Could you help me with this issue ?

Thank you,
Fabrice
-------------
Posted 29 Apr, 2021 19:57:07 Top
Andrei Smolin


Add-in Express team


Posts: 18007
Joined: 2006-05-11
Hello Fabrice,

I assume this issue can't be solved. I reproduce it in Outlook 365 Version 2103 (Build 13901.20462 Click-to-Run) Current Channel with all COM add-ins turned off.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Apr, 2021 04:46:27 Top
Fabrice




Posts: 158
Joined: 2010-12-13
Hello Andrei, did you run the test code I sent ?

For my customer it's quite simple:
- They disable my add-in ==> No problem
- They enable my add-in ==> problem

Exactly like the reprod I sent you.
So maybe you reproduce it without com add-in on your side, but on my side without the add-in I don't have the problem.
Btw I read your post in a link saying it was solved in outlook ;)
-------------
Posted 30 Apr, 2021 05:35:36 Top
Andrei Smolin


Add-in Express team


Posts: 18007
Joined: 2006-05-11
Hello Fabrice,

I did try it. And reproduced the issue. I've checked how you release COM objects: you do this perfectly. But it turned out I can reproduce this issue with *absolutely* all COM add-ins turned off; absolutely means "your add-in was turned off, too". That is, the issue belongs to Outlook installed on *my* machine. Since you reproduce it, I suppose you use an Outlook build other than the Current Channel build installed on my machine.

You can't fix this issue as it occurs outside of your code.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Apr, 2021 06:03:04 Top
Fabrice




Posts: 158
Joined: 2010-12-13
Ok I understand
But it would be easier for me to tell that to the customer if they also had the problem without my addin. I don't think this explanation will be accepted. If you search this problem on internet, 99% of answers is "disable all add-in" and that fix the problem most of time... like in my case !

Is it any way to detect an email is opened from the disk ?
-------------
Posted 30 Apr, 2021 07:32:23 Top
Fabrice




Posts: 158
Joined: 2010-12-13
Btw, on my non-dev laptop with Outlook 365 version 2104 I've the same behavior: file locked only when my add-in is loaded.
-------------
Posted 30 Apr, 2021 07:55:24 Top
Andrei Smolin


Add-in Express team


Posts: 18007
Joined: 2006-05-11
Hello Fabrice,

Please don't assume I hide some solution from you.

The problem is: *my* Outlook shows this message with *no* add-ins at all. I use the most new Outlook build, meaning "99% of answers" apply to older Outlook builds. And, once your customer installs the Outlook build that I use, you'll get the issue anew. That is, assuming Microsoft don't fix it on their side.

Of course, I remember this scenario. I do remember I wrote about it both somewhere and somewhere else, too. I assume, this issue evolves along with Outlook and, if you fix this issue for now, you'll get it "tomorrow".

When trying to solve this issue, remember that the Outlook build that you use may differ in several respects.

You could try to disconnect from the item in InspectorDeactivate.

This would only work if Deactivate occurs *before* Activate (of another Inspector or Explorer). This is so in my Outlook build.

BUT... We DO know (for years!) that switching from one inspector to another produced the Activate event on the second inspector first and the Desactivate event on the first inspector then.

If this is your case, too, you'd need to completely rewrite the inner logic of the add-in. Instead of managing a single events class instance, you would need to manage several class instances so that the events class instance associated with a given inspector connects when the inspector activates and disconnects when the inspector deactivates. This approach complicates the logic immensely.

Fabrice writes:
Is it any way to detect an email is opened from the disk ?


No. Also note that the issue occurs before any Outlook inspector-related event occurs. I've noticed however that the InspectorDeactivate event also occurs (for me) when I switch from Outlook to Windows Explorer. If this event occurs to you, you can try to use it.

I remind you that in my Outlook no add-in is required to produce the issue. An add-in cannot fix issues in its host application.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Apr, 2021 08:54:27 Top
Andrei Smolin


Add-in Express team


Posts: 18007
Joined: 2006-05-11
Fabrice writes:
Btw, on my non-dev laptop with Outlook 365 version 2104 I've the same behavior: file locked only when my add-in is loaded.


This issue occurs for me in Outlook Version 2104 (Build 13929.20296 Click-to-Run) Current Channel with all COM add-ins turned off.

User added an image

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Apr, 2021 09:09:03 Top
Fabrice




Posts: 158
Joined: 2010-12-13
Andrei, I don't assume you hide any solution. I'm using ADX since +7years and you always offered one of the best support, thank you for that.

Im just trying to find either a solution, either a way to demonstrate this is not something I can handle in the add-in.
I'll try to play with the (de)activate event to see if there is some hope.

I already tried many different ways to FinalReleaseComObject on the inspector and just succeeded to crash outlook :)
-------------
Posted 30 Apr, 2021 10:28:39 Top
Fabrice




Posts: 158
Joined: 2010-12-13
Hello Andrei,
Trying to disconnect in the deactivate event doesn't works

Just a question: if in the InspectorClosed event I
- Disconnect
- FinalRelease the inspector (I know it's a object given by ADX so I shouldn't do that, but I tried)
- Send%essage and when received I do a GCCollect.
In this case the file is not locked anymore when I close the email. I can reopen it without problem.
But (of course) ... the "only" problem, is that I've a COM exception from add-in express when closing the email at the 2nd open
So
- open
- close
- open
- close => exception

Date and Time:         02-05-21 15:16:00
Machine Name:          DESKTOP-M8O4K0D
IP Address:            xxx
Current User:          DESKTOP-M8O4K0DFabrice

Application Domain:    C:ProjectsTestsAddin-ExpressTestReplyEventAddinEmptyAddininDebug
Assembly Codebase:     file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
Assembly Full Name:    mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Assembly Version:      4.0.0.0
Assembly Build Date:   10-02-21 00:13:42

Exception Source:      mscorlib
Exception Type:        System.Runtime.InteropServices.InvalidComObjectException
Exception Message:     Impossible d'utiliser un objet COM qui a été séparé de son RCW sous-jacent.
Exception Target Site: GetIUnknownForObjectNative

---- Stack Trace ----
   System.Runtime.InteropServices.Marshal.GetIUnknownForObjectNative(o As Object, onlyInContext As Boolean)
       AddinExpress.OL.2005.dll: N 00000 (0x0) JIT 
   System.Runtime.InteropServices.Marshal.GetIUnknownForObject(o As Object)
       AddinExpress.OL.2005.dll: N 0000 (0x0) IL 
   AddinExpress.OL.OutlookUtils.NewRefObj(Obj As Object)
       AddinExpress.OL.2005.dll: N 0010 (0xA) IL 
   AddinExpress.OL.ADXOlInspectorArguments..ctor(FormsManager As ADXOlFormsManager, InspectorObj As Object, ItemObj As Object, InspectorWindowHandle As IntPtr, CodeContext As ADXOlCodeContext)
       AddinExpress.OL.2005.dll: N 0244 (0xF4) IL 
   AddinExpress.OL.OlInspectorEvents_BaseLogic.DoInspectorActivate()
       AddinExpress.OL.2005.dll: N 0052 (0x34) IL 
   AddinExpress.OL.OlInspectorEvents_10_SinkHelper.AddinExpress.OL.IInspectorEvents_10.Activate()
       AddinExpress.OL.2005.dll: N 0026 (0x1A) IL 


COM object that has been separated from its underlying RCW cannot be used

I would expect to have that after the 1st close, not the second. Is it possible that ADX keep a link to the 1st email opened ? That would explain the error.
-------------
Posted 03 May, 2021 02:37:19 Top