diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
index 8538e63c068801..a6351198a2c595 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
@@ -300,6 +300,7 @@ public static void RegisterForTrackerSupport(ComWrappers instance)
/// * P/Invokes with COM-related types
/// * COM activation
///
+ [SupportedOSPlatform("windows")]
public static void RegisterForMarshalling(ComWrappers instance)
{
if (instance == null)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs
index 2cfac1e1919e90..f2701035b93ab5 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.PlatformNotSupported.cs
@@ -41,6 +41,7 @@ public static void RegisterForTrackerSupport(ComWrappers instance)
throw new PlatformNotSupportedException();
}
+ [SupportedOSPlatform("windows")]
public static void RegisterForMarshalling(ComWrappers instance)
{
throw new PlatformNotSupportedException();
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
index 72019f3d833cc4..ff16e14d4e39d5 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs
@@ -69,7 +69,11 @@ public enum CreateObjectFlags
///
/// Class for managing wrappers of COM IUnknown types.
///
- [SupportedOSPlatform("windows")]
+ [UnsupportedOSPlatform("android")]
+ [UnsupportedOSPlatform("browser")]
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("maccatalyst")]
+ [UnsupportedOSPlatform("tvos")]
[CLSCompliant(false)]
public abstract partial class ComWrappers
{
diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs
index e6c03d03d24181..feb8ae7135abb5 100644
--- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs
+++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs
@@ -1125,7 +1125,11 @@ public enum CreateObjectFlags
Aggregation = 4,
Unwrap = 8,
}
- [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
+ [System.Runtime.Versioning.UnsupportedOSPlatform("android")]
+ [System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
+ [System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatform("maccatalyst")]
+ [System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
[System.CLSCompliantAttribute(false)]
public abstract class ComWrappers
{
@@ -1147,6 +1151,7 @@ public struct ComInterfaceDispatch
public object GetOrRegisterObjectForComInstance(System.IntPtr externalComObject, CreateObjectFlags flags, object wrapper, System.IntPtr inner) { throw null; }
protected abstract void ReleaseObjects(System.Collections.IEnumerable objects);
public static void RegisterForTrackerSupport(ComWrappers instance) { }
+ [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static void RegisterForMarshalling(ComWrappers instance) { }
protected static void GetIUnknownImpl(out System.IntPtr fpQueryInterface, out System.IntPtr fpAddRef, out System.IntPtr fpRelease) { throw null; }
}
diff --git a/src/libraries/System.Runtime.InteropServices/src/MatchingRefApiCompatBaseline.txt b/src/libraries/System.Runtime.InteropServices/src/MatchingRefApiCompatBaseline.txt
index 8a50ec864714be..dd2e06b69c3c29 100644
--- a/src/libraries/System.Runtime.InteropServices/src/MatchingRefApiCompatBaseline.txt
+++ b/src/libraries/System.Runtime.InteropServices/src/MatchingRefApiCompatBaseline.txt
@@ -1,5 +1,6 @@
Compat issues with assembly System.Runtime.InteropServices:
TypesMustExist : Type 'System.Runtime.InteropServices.AssemblyRegistrationFlags' does not exist in the reference but it does exist in the implementation.
+CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Runtime.InteropServices.ComWrappers' changed from '[UnsupportedOSPlatformAttribute("android")]' in the implementation to '[UnsupportedOSPlatformAttribute("android")]' in the reference.
TypesMustExist : Type 'System.Runtime.InteropServices.ExporterEventKind' does not exist in the reference but it does exist in the implementation.
TypesMustExist : Type 'System.Runtime.InteropServices.IDispatchImplAttribute' does not exist in the reference but it does exist in the implementation.
TypesMustExist : Type 'System.Runtime.InteropServices.IDispatchImplType' does not exist in the reference but it does exist in the implementation.
@@ -7,5 +8,4 @@ TypesMustExist : Type 'System.Runtime.InteropServices.RegistrationClassContext'
TypesMustExist : Type 'System.Runtime.InteropServices.RegistrationConnectionType' does not exist in the reference but it does exist in the implementation.
TypesMustExist : Type 'System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public void System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute..ctor()' does not exist in the reference but it does exist in the implementation.
-CannotRemoveAttribute : Attribute 'System.CLSCompliantAttribute' exists on 'System.Runtime.InteropServices.ComTypes.IDataObject' in the implementation but not the reference.
Total Issues: 9
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj
index f0ffe70d47c314..5235b8023a63dd 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj
+++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj
@@ -137,6 +137,7 @@
+
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/AddRefTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/AddRefTests.cs
index c8cd89168b3526..ec5ae351bc79c0 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/AddRefTests.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/AddRefTests.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Runtime.InteropServices.Tests.Common;
using Xunit;
namespace System.Runtime.InteropServices.Tests
@@ -8,10 +9,11 @@ namespace System.Runtime.InteropServices.Tests
public class AddRefTests
{
[Fact]
- [PlatformSpecific(TestPlatforms.Windows)]
+ [SkipOnMono("ComWrappers are not supported on Mono")]
public void AddRef_ValidPointer_Success()
{
- IntPtr iUnknown = Marshal.GetIUnknownForObject(new object());
+ var cw = new ComWrappersImpl();
+ IntPtr iUnknown = cw.GetOrCreateComInterfaceForObject(new object(), CreateComInterfaceFlags.None);
try
{
Assert.Equal(2, Marshal.AddRef(iUnknown));
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/Common/COMWrappersImpl.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/Common/COMWrappersImpl.cs
new file mode 100644
index 00000000000000..f6b7180c299e3b
--- /dev/null
+++ b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/Common/COMWrappersImpl.cs
@@ -0,0 +1,43 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Collections;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+namespace System.Runtime.InteropServices.Tests.Common
+{
+ public class ComWrappersImpl : ComWrappers
+ {
+ // Doesn't represent a real interface. The value is only used to support a call to QueryInterface for testing.
+ public const string IID_TestQueryInterface = "1F906666-B388-4729-B78C-826BC5FD4245";
+
+ protected unsafe override ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count)
+ {
+ Assert.Equal(CreateComInterfaceFlags.None, flags);
+
+ IntPtr fpQueryInterface = default;
+ IntPtr fpAddRef = default;
+ IntPtr fpRelease = default;
+ ComWrappers.GetIUnknownImpl(out fpQueryInterface, out fpAddRef, out fpRelease);
+
+ var vtblRaw = (IntPtr*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComWrappersImpl), IntPtr.Size * 3);
+ vtblRaw[0] = fpQueryInterface;
+ vtblRaw[1] = fpAddRef;
+ vtblRaw[2] = fpRelease;
+
+ var entryRaw = (ComInterfaceEntry*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComWrappersImpl), sizeof(ComInterfaceEntry));
+ entryRaw->IID = new Guid(IID_TestQueryInterface);
+ entryRaw->Vtable = (IntPtr)vtblRaw;
+
+ count = 1;
+ return entryRaw;
+ }
+
+ protected override object CreateObject(IntPtr externalComObject, CreateObjectFlags flag)
+ => throw new NotImplementedException();
+
+ protected override void ReleaseObjects(IEnumerable objects)
+ => throw new NotImplementedException();
+ }
+}
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs
index 30657253cc8248..74ffdaad3b2dbd 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs
@@ -9,6 +9,7 @@ namespace System.Runtime.InteropServices.Tests
{
public partial class QueryInterfaceTests
{
+ public const string IID_IDISPATCH = "00020400-0000-0000-C000-000000000046";
public const string IID_IINSPECTABLE = "AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90";
public static IEnumerable