diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/NativeMarshallingAttributeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/NativeMarshallingAttributeTests.cs index 22d71f56ea093e..b06b6c0709064e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/NativeMarshallingAttributeTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.Tests/NativeMarshallingAttributeTests.cs @@ -17,7 +17,6 @@ partial class NativeExportsNE public class NativeMarshallingAttributeTests { [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsCoreCLR))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/122447")] public void GetSameComInterfaceTwiceReturnsUniqueInstances() { // When using NativeMarshalling with UniqueComInterfaceMarshaller, diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/UniqueMarshalling.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/UniqueMarshalling.cs index f7dc257e01261f..371a973076e97b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/UniqueMarshalling.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/ComInterfaceGenerator/UniqueMarshalling.cs @@ -10,6 +10,8 @@ namespace NativeExports.ComInterfaceGenerator public static unsafe class UniqueMarshalling { private static void* s_cachedPtr = null; + // To handle the final release of the cached pointer + private static ComObject s_cachedObject = null; // Call from another assembly to get a ptr to make an RCW [UnmanagedCallersOnly(EntryPoint = "new_unique_marshalling")] @@ -20,9 +22,12 @@ public static unsafe class UniqueMarshalling StrategyBasedComWrappers wrappers = new(); var myObject = new SharedTypes.ComInterfaces.UniqueMarshalling(); nint ptr = wrappers.GetOrCreateComInterfaceForObject(myObject, CreateComInterfaceFlags.None); + s_cachedObject = (ComObject)wrappers.GetOrCreateObjectForComInstance(ptr, CreateObjectFlags.None); s_cachedPtr = (void*)ptr; } + // AddRef before returning - caller will Release + Marshal.AddRef((nint)s_cachedPtr); return s_cachedPtr; } }