diff --git a/UnitTest/TestComponentCSharp_Tests.cs b/UnitTest/TestComponentCSharp_Tests.cs index e31c0eadd..743957447 100644 --- a/UnitTest/TestComponentCSharp_Tests.cs +++ b/UnitTest/TestComponentCSharp_Tests.cs @@ -1496,5 +1496,12 @@ public void WeakReferenceOfNativeObjectRehydratedAfterWrapperIsCollected() Assert.True(winrt.TryGetTarget(out _)); GC.KeepAlive(objRef); } + + [Fact] + public void TestUnwrapInspectable() + { + var inspectable = IInspectable.FromAbi(TestObject.ThisPtr); + Assert.True(ComWrappersSupport.TryUnwrapObject(inspectable, out _)); + } } } diff --git a/WinRT.Runtime/IInspectable.cs b/WinRT.Runtime/IInspectable.cs index 82cfc18b6..ea4a3444f 100644 --- a/WinRT.Runtime/IInspectable.cs +++ b/WinRT.Runtime/IInspectable.cs @@ -14,6 +14,7 @@ public enum TrustLevel } // IInspectable + [ObjectReferenceWrapper(nameof(_obj))] [Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")] public class IInspectable { @@ -104,9 +105,9 @@ public unsafe string GetRuntimeClassName(bool noThrow = false) try { var hr = _obj.Vftbl.GetRuntimeClassName(ThisPtr, out __retval); - if (hr != 0) - { - if (noThrow) + if (hr != 0) + { + if (noThrow) return null; Marshal.ThrowExceptionForHR(hr); }