GetIUnknownForObjectNative exception

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

GetIUnknownForObjectNative exception
 
Subscribe
Sébastien Lange




Posts: 25
Joined: 2022-09-21
Hi,

I have created a very limited VSTO add-in (with Region for Outlook and VSTO) to be able to filter public folders post items.

ADXOlForm.ExplorerObj is used. I do not release it. I'm getting CurrentView object, but I release it as you can see in code hereafter.


        public void ApplyViewFilter(Explorer explorer, string filter)
        {
            if (explorer == null) return;

            using (var currentView = new ComObject<View>(explorer.CurrentView))
            {
                var view = currentView.WrappedObject;
                if (string.IsNullOrWhiteSpace(filter))
                {
                    view.Filter = filter;
                    view.Reset();
                }
                else
                {
                    view.Filter = filter;
                    view.Save();
                }
                view.Apply();
            }
        }


I provide also the code of ComObject:


    public class ComObject<T> : IDisposable where T : class
    {
        public T WrappedObject { get; }

        public ComObject(T value)
        {
            WrappedObject = value;
        }

        public static void Release(params object[] args)
        {
            foreach (var o in args)
            {
                if (o != null && Marshal.IsComObject(o))
                {
                    Marshal.ReleaseComObject(o);
                }
            }
        }

        public void Dispose()
        {
            GC.SuppressFinalize(this);
            Release(WrappedObject);
        }

        ~ComObject()
        {
            Release(WrappedObject);
        }
    }


However, we often have the exception below that seems related to InspectorObj.
In my code, I never use ADXOlForm.InspectorObj in this add-in...

Could you provide some help to understand why I have this exception?
Do I have any opportunity to catch and log this exception?

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.Outlook.Regions.DLL: N 00000 (0x0) JIT
AddinExpress.OL.OutlookUtils.NewRefObj(Obj As Object)
AddinExpress.Outlook.Regions.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.Outlook.Regions.DLL: N 0244 (0xF4) IL
AddinExpress.OL.OlInspectorEvents_BaseLogic.DoInspectorActivate()
AddinExpress.Outlook.Regions.DLL: N 0058 (0x3A) IL
AddinExpress.OL.OlInspectorEvents_10_SinkHelper.AddinExpress.OL.IInspectorEvents_10.Activate()
AddinExpress.Outlook.Regions.DLL: N 0032 (0x20) IL


Best regards,
Sébastien
Posted 20 Oct, 2022 07:48:09 Top
Sébastien Lange




Posts: 25
Joined: 2022-09-21
The exeception happens when opening or trying to close an inspector window.
When trying to close it, it's fired multiple times and it's impossible to close the window.
Posted 21 Oct, 2022 05:17:50 Top
Andrei Smolin


Add-in Express team


Posts: 18515
Joined: 2006-05-11
Hello Sébastien,

Regarding the ComObject class: it allows releasing a wrapped object twice: when the class instance is disposed and when the class instance is destroyed. To make sure this never occurs you can nullify the wrapped object after releasing it; you'll also need you only release a non-null object.

As to your other issue, please send us your project (or any project reproducing the issue) to the support email address; find it in {Add-in Express installation folder}\readme.txt.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 21 Oct, 2022 05:41:10 Top