diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index a81acbe1c6218..8851446e6b2b5 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -129,6 +129,21 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly() public static bool IsInContainer => GetIsInContainer(); public static bool SupportsComInterop => IsWindows && IsNotMonoRuntime && !IsNativeAot; // matches definitions in clr.featuredefines.props + +#if NETCOREAPP + public static bool IsBuiltInComEnabled => SupportsComInterop + && (AppContext.TryGetSwitch("System.Runtime.InteropServices.BuiltInComInterop.IsSupported", out bool isEnabled) + ? isEnabled + : true); +#else + public static bool IsBuiltInComEnabled => SupportsComInterop; +#endif + + // Automation refers to OLE Automation support. Automation support here means the OS + // and runtime provide support for the following: IDispatch, STA apartments, etc. This + // is typically available whenever COM support is enabled, but Windows Nano Server is an exception. + public static bool IsBuiltInComEnabledWithOSAutomationSupport => IsBuiltInComEnabled && IsNotWindowsNanoServer; + public static bool SupportsSsl3 => GetSsl3Support(); public static bool SupportsSsl2 => IsWindows && !PlatformDetection.IsWindows10Version1607OrGreater; diff --git a/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj b/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj index ad86c57c9f904..fc2048c219ac9 100644 --- a/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj +++ b/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj @@ -37,7 +37,6 @@ - diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/SetWin32ContextInIDispatchAttribute.cs b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/SetWin32ContextInIDispatchAttribute.cs deleted file mode 100644 index 6d214badb2879..0000000000000 --- a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/SetWin32ContextInIDispatchAttribute.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace System.Runtime.InteropServices -{ - [Obsolete("SetWin32ContextInIDispatchAttribute has been deprecated. Application Domains no longer respect Activation Context boundaries in IDispatch calls.")] - [AttributeUsage(AttributeTargets.Assembly, Inherited = false)] - public sealed class SetWin32ContextInIDispatchAttribute : Attribute - { - public SetWin32ContextInIDispatchAttribute() - { - } - } -} diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj index d39b569ec036f..34964fb33f2ab 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj @@ -159,7 +159,6 @@ - diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComAwareEventInfoTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComAwareEventInfoTests.Windows.cs index 871ada5dfc06a..54a58cfacdb98 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComAwareEventInfoTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComAwareEventInfoTests.Windows.cs @@ -22,7 +22,7 @@ public class DispAttributeClass public void Event() { } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void AddEventHandler_ComObjectWithoutComEventInterfaceAttribute_ThrowsInvalidOperationException() { var attribute = new ComAwareEventInfo(typeof(NonComObject), nameof(NonComObject.Event)); @@ -33,7 +33,7 @@ public void AddEventHandler_ComObjectWithoutComEventInterfaceAttribute_ThrowsInv Assert.Throws(() => attribute.RemoveEventHandler(target, handler)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void AddEventHandler_ComObjectWithMultipleComEventInterfaceAttribute_ThrowsAmbiguousMatchException() { // C# doesn't let us apply multiple ComEventInterface values, so RefEmit is necessary. @@ -57,7 +57,7 @@ public void AddEventHandler_ComObjectWithMultipleComEventInterfaceAttribute_Thro Assert.Throws(() => attribute.RemoveEventHandler(target, handler)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void AddEventHandler_NullSourceTypeEventInterface_ThrowsNullReferenceException() { var attribute = new ComAwareEventInfo(typeof(NullSourceType), nameof(NullSourceType.Event)); @@ -74,7 +74,7 @@ public interface NullSourceType event EventHandler Event; } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void AddEventHandler_NoSuchSourceTypeEventInterface_ThrowsArgumentNullException() { var attribute = new ComAwareEventInfo(typeof(NoSuchSourceType), nameof(NoSuchSourceType.Event)); @@ -91,7 +91,7 @@ public interface NoSuchSourceType event EventHandler Event; } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void AddEventHandler_NoDispIdAttribute_ThrowsInvalidOperationException() { var attribute = new ComAwareEventInfo(typeof(NoDispAttributeInterface), nameof(NoDispAttributeInterface.Event)); @@ -102,7 +102,7 @@ public void AddEventHandler_NoDispIdAttribute_ThrowsInvalidOperationException() Assert.Throws(() => attribute.RemoveEventHandler(target, handler)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void AddEventHandler_TargetNotIConnectionIConnectionPointContainer_ThrowsInvalidCastException() { var attribute = new ComAwareEventInfo(typeof(DispAttributeInterface), nameof(DispAttributeInterface.Event)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComEventsHelperTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComEventsHelperTests.cs index 1e9be2d697195..44ee17e16e20d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComEventsHelperTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComEventsHelperTests.cs @@ -14,15 +14,13 @@ public void Combine_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => ComEventsHelper.Combine(null, Guid.Empty, 1, null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void Combine_NullRcw_ThrowsArgumentNullException() { AssertExtensions.Throws(null, () => ComEventsHelper.Combine(null, Guid.Empty, 1, null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void Combine_NotComObject_ThrowsArgumentException() { AssertExtensions.Throws("obj", () => ComEventsHelper.Combine(1, Guid.Empty, 1, null)); @@ -35,15 +33,13 @@ public void Remove_Unix_ThrowPlatformNotSupportedException() Assert.Throws(() => ComEventsHelper.Remove(null, Guid.Empty, 1, null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void Remove_NullRcw_ThrowsArgumentNullException() { AssertExtensions.Throws(null, () => ComEventsHelper.Remove(null, Guid.Empty, 1, null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void Remove_NotComObject_ThrowsArgumentException() { AssertExtensions.Throws("obj", () => ComEventsHelper.Remove(1, Guid.Empty, 1, null)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComVisibleAttributeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComVisibleAttributeTests.cs index 516c92ab87bfb..a7356312e602e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComVisibleAttributeTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ComVisibleAttributeTests.cs @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices.Tests [ComVisible(true)] public class ComVisibleAttributeTests { - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void Exists() { Type type = typeof(ComVisibleAttributeTests); @@ -16,7 +16,7 @@ public void Exists() Assert.True(attribute.Value); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData(true)] [InlineData(false)] public void Ctor_Visible(bool visibility) diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/DispatchWrapperTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/DispatchWrapperTests.cs index 12211549fe006..4317cfa4c9b3e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/DispatchWrapperTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/DispatchWrapperTests.cs @@ -23,10 +23,9 @@ public void Ctor_NonNull_ThrowsPlatformNotSupportedException(object value) Assert.Throws(() => new DispatchWrapper(value)); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData("")] [InlineData(0)] - [PlatformSpecific(TestPlatforms.Windows)] public void Ctor_NonDispatchObject_ThrowsInvalidCastException(object value) { Assert.Throws(() => new DispatchWrapper(value)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.Windows.cs index 6579678cd309c..184308df8950c 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.Windows.cs @@ -26,7 +26,7 @@ public static IEnumerable ChangeWrapperHandleStrength_ComObject_TestDa yield return new object[] { new AutoDualComObjectEmpty() }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(ChangeWrapperHandleStrength_ComObject_TestData))] public void ChangeWrapperHandleStrength_ComObject_ReturnsExpected(object o) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.cs index 2880738b581d8..305ecf491694e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.cs @@ -33,8 +33,7 @@ public static IEnumerable ChangeWrapperHandleStrength_TestData() yield return new object[] { d }; } - [Theory] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(ChangeWrapperHandleStrength_TestData))] public void ChangeWrapperHandleStrength_ValidObject_Success(object otp) { @@ -42,8 +41,7 @@ public void ChangeWrapperHandleStrength_ValidObject_Success(object otp) Marshal.ChangeWrapperHandleStrength(otp, fIsWeak: false); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void ChangeWrapperHandleStrength_NullObject_ThrowsArgumentNullException() { AssertExtensions.Throws("otp", () => Marshal.ChangeWrapperHandleStrength(null, fIsWeak: true)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.Windows.cs index 1cf889d5a158f..d82ea0d5a2f5a 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.Windows.cs @@ -3,10 +3,13 @@ #pragma warning disable CS0618 // Type or member is obsolete +using System.Runtime.CompilerServices; +using System.Threading; + namespace System.Runtime.InteropServices.Tests.Common { [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid("293E13A4-2791-4121-9714-14D37CF5DCD4")] public interface IComImportObject { } [ComImport] @@ -31,31 +34,263 @@ public interface IInspectableInterface { } public class InterfaceComImportObject : IComImportObject { } + /// + /// Well-known COM constants + /// + public static class ComConstants + { + public static readonly Guid IID_IUnknown = new("00000000-0000-0000-c000-000000000046"); + public static readonly Guid IID_IDispatch = new("00020400-0000-0000-c000-000000000046"); + public static readonly Guid IID_IClassFactory = new("00000001-0000-0000-c000-000000000046"); + + public const int S_OK = 0; + public const int E_NOTIMPL = unchecked((int)0x80004001); + public const int E_NOINTERFACE = unchecked((int)0x80004002); + } + + /// + /// Class factory used to provide a unmanaged IClassFactory instance for testing with . + /// + internal unsafe struct ComObjectFactory + { + public const string CLSID = "3DCAAC37-F484-49E9-9257-273BA9618162"; + + [ModuleInitializer] + internal static unsafe void RegisterInProcCOMServer() + { + var clsid = new Guid(ComObjectFactory.CLSID); + const int CLSCTX_INPROC_SERVER = 1; + const int REGCLS_MULTIPLEUSE = 1; + void* classFactory = ComObjectFactory.Create(); + int res = CoRegisterClassObject(in clsid, classFactory, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, out int cookie); + Xunit.Assert.Equal(ComConstants.S_OK, res); + Marshal.Release((IntPtr)classFactory); + + [DllImport("Ole32")] + static extern int CoRegisterClassObject(in Guid clsid, void* factory, int clsContext, int flags, out int registerCookie); + } + + // Create an instance of a COM object class factory + public static void* Create() + { + var vtable = (VTable*)NativeMemory.Alloc((nuint)sizeof(VTable)); + vtable->QueryInterface = &QueryInterface; + vtable->AddRef = &AddRef; + vtable->Release = &Release; + + vtable->CreateInstance = &CreateInstance; + vtable->LockServer = &LockServer; + + var instance = (ComObjectFactory*)NativeMemory.Alloc((nuint)sizeof(ComObjectFactory)); + instance->_vtable = vtable; + instance->_refCount = 1; + return instance; + } + + // The COM ABI for a vtable + private struct VTable + { + // IUnknown + public delegate* unmanaged QueryInterface; + public delegate* unmanaged AddRef; + public delegate* unmanaged Release; + + // IClassFactory + public delegate* unmanaged CreateInstance; + public delegate* unmanaged LockServer; + } + + // The COM ABI requires the first pointer field to be the vtable + private VTable* _vtable; + + // Additional instance fields for this COM object + private uint _refCount; + + [UnmanagedCallersOnly] + private static int QueryInterface(void* instance, Guid* iid, void** obj) + { + if (ComConstants.IID_IUnknown == *iid || ComConstants.IID_IClassFactory == *iid) + { + *obj = instance; + } + else + { + return ComConstants.E_NOINTERFACE; + } + + _AddRef(instance); + return ComConstants.S_OK; + } + + [UnmanagedCallersOnly] + private static uint AddRef(void* instance) => _AddRef(instance); + + private static uint _AddRef(void* instance) + { + var inst = (ComObjectFactory*)instance; + return Interlocked.Increment(ref inst->_refCount); + } + + [UnmanagedCallersOnly] + private static uint Release(void* instance) + { + var inst = (ComObjectFactory*)instance; + uint c = Interlocked.Decrement(ref inst->_refCount); + if (c == 0) + { + NativeMemory.Free(inst->_vtable); + NativeMemory.Free(inst); + } + return c; + } + + [UnmanagedCallersOnly] + private static int CreateInstance(void* instance, void* outer, Guid* riid, void** obj) + { + *obj = ComObject.Create(); + return ComConstants.S_OK; + } + + [UnmanagedCallersOnly] + private static int LockServer(void* instance, int shouldLock) => ComConstants.S_OK; + } + + /// + /// ComObject defined entirely in managed code to avoid requiring a known registered COM server. + /// + internal unsafe struct ComObject + { + // Create an instance of a COM object + public static void* Create() + { + var vtable = (VTable*)NativeMemory.Alloc((nuint)sizeof(VTable)); + vtable->QueryInterface = &QueryInterface; + vtable->AddRef = &AddRef; + vtable->Release = &Release; + + vtable->GetTypeInfoCount = &GetTypeInfoCount; + vtable->GetTypeInfo = &GetTypeInfo; + vtable->GetIDsOfNames = &GetIDsOfNames; + vtable->Invoke = &Invoke; + + var instance = (ComObject*)NativeMemory.Alloc((nuint)sizeof(ComObject)); + instance->_vtable = vtable; + instance->_refCount = 1; + return instance; + } + + // The COM ABI for a vtable + private struct VTable + { + // IUnknown + public delegate* unmanaged QueryInterface; + public delegate* unmanaged AddRef; + public delegate* unmanaged Release; + + // IDispatch + public delegate* unmanaged GetTypeInfoCount; + public delegate* unmanaged GetTypeInfo; + public delegate* unmanaged GetIDsOfNames; + public delegate* unmanaged Invoke; + } + + // The COM ABI requires the first pointer field to be the vtable + private VTable* _vtable; + + // Additional instance fields for this COM object + private uint _refCount; + + [UnmanagedCallersOnly] + private static int QueryInterface(void* instance, Guid* iid, void** obj) + { + if (ComConstants.IID_IUnknown == *iid || ComConstants.IID_IDispatch == *iid) + { + *obj = instance; + } + else + { + return ComConstants.E_NOINTERFACE; + } + + _AddRef(instance); + return ComConstants.S_OK; + } + + [UnmanagedCallersOnly] + private static uint AddRef(void* instance) => _AddRef(instance); + + private static uint _AddRef(void* instance) + { + var inst = (ComObject*)instance; + return Interlocked.Increment(ref inst->_refCount); + } + + [UnmanagedCallersOnly] + private static uint Release(void* instance) + { + var inst = (ComObject*)instance; + uint c = Interlocked.Decrement(ref inst->_refCount); + if (c == 0) + { + NativeMemory.Free(inst->_vtable); + NativeMemory.Free(inst); + } + return c; + } + + [UnmanagedCallersOnly] + private static int GetTypeInfoCount(void* instance, uint* i) => ComConstants.E_NOTIMPL; + + [UnmanagedCallersOnly] + private static int GetTypeInfo(void* instance, int itinfo, int lcid, void** i) => ComConstants.E_NOTIMPL; + + [UnmanagedCallersOnly] + private static int GetIDsOfNames( + void* instance, + Guid* iid, + void** namesRaw, + uint namesCount, + uint lcid, + int* dispIdsRaw) => ComConstants.E_NOTIMPL; + + [UnmanagedCallersOnly] + private static int Invoke( + void* instance, + int dispIdMember, + Guid* riid, + uint lcid, + short wFlags, + void* pDispParams, + void* VarResult, + void* pExcepInfo, + void* puArgErr) => ComConstants.E_NOTIMPL; + } + [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] - public class InterfaceAndComImportObject : IComImportObject { } + [Guid(ComObjectFactory.CLSID)] + public class InterfaceOnComImportObject : IComImportObject { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] public class ComImportObject { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.None)] public class DualComObject : DualInterface { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.None)] public class IUnknownComObject : IUnknownInterface { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.None)] public class IDispatchComObject : IDispatchInterface { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.None)] public class IInspectableComObject : IInspectableInterface { } @@ -66,32 +301,32 @@ public class SubComImportObject : ComImportObject { } public class GenericSubComImportObject : ComImportObject { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.None)] public class NonDualComObject : IComImportObject { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.None)] public class NonDualComObjectEmpty { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.AutoDispatch)] public class AutoDispatchComObject : IComImportObject { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.AutoDispatch)] public class AutoDispatchComObjectEmpty { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.AutoDual)] public class AutoDualComObject : IComImportObject { } [ComImport] - [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")] + [Guid(ComObjectFactory.CLSID)] [ClassInterface(ClassInterfaceType.AutoDual)] public class AutoDualComObjectEmpty { } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateAggregatedObjectTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateAggregatedObjectTests.cs index ccef2801a2d30..a7837f9688ab1 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateAggregatedObjectTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateAggregatedObjectTests.cs @@ -9,8 +9,7 @@ namespace System.Runtime.InteropServices.Tests { public partial class CreateAggregatedObjectTests { - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void CreateAggregatedObject_Generic_ReturnsExpected() { var original = new object(); @@ -38,8 +37,7 @@ public void CreateAggregatedObject_Generic_ReturnsExpected() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void CreateAggregatedObject_NonGeneric_ReturnsExpected() { var original = new object(); @@ -74,22 +72,19 @@ public void CreateAggregatedObject_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.CreateAggregatedObject(IntPtr.Zero, 1)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void CreateAggregateObject_ZeroPointer_ThrowsArgumentNullException() { AssertExtensions.Throws("pOuter", () => Marshal.CreateAggregatedObject(IntPtr.Zero, 1)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void CreateAggregateObject_NullObject_ThrowsArgumentNullException() { AssertExtensions.Throws("o", () => Marshal.CreateAggregatedObject((IntPtr)1, null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void CreateAggregatedObject_AlreadyHasContainer_ThrowsArgumentException() { var o1 = new object(); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateWrapperOfTypeTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateWrapperOfTypeTests.Windows.cs index 41f7f46eb54d2..65cfd71c03838 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateWrapperOfTypeTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateWrapperOfTypeTests.Windows.cs @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices.Tests { public partial class CreateWrapperOfTypeTests { - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void CreateWrapperOfType_SameType_ReturnsSameInstance() { var comObject = new ComImportObject(); @@ -16,14 +16,14 @@ public void CreateWrapperOfType_SameType_ReturnsSameInstance() Assert.Same(comObject, Marshal.CreateWrapperOfType(comObject)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void CreateWrapperOfType_NullObject_ReturnsNull() { Assert.Null(Marshal.CreateWrapperOfType(null, typeof(ComImportObject))); Assert.Null(Marshal.CreateWrapperOfType(null)); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData(typeof(int))] [InlineData(typeof(GenericSubComImportObject))] [InlineData(typeof(GenericSubComImportObject<>))] @@ -32,7 +32,7 @@ public void CreateWrapperOfType_InvalidComObjectType_ThrowsArgumentException(Typ AssertExtensions.Throws("t", () => Marshal.CreateWrapperOfType(new ComImportObject(), t)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void CreateWrappedOfType_ObjectNotComObject_ThrowsArgumentException() { AssertExtensions.Throws("o", () => Marshal.CreateWrapperOfType(10, typeof(ComImportObject))); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateWrapperOfTypeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateWrapperOfTypeTests.cs index 72eda70ae523f..eea194a3af64b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateWrapperOfTypeTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/CreateWrapperOfTypeTests.cs @@ -14,8 +14,7 @@ public void CreateWrapperOfType_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.CreateWrapperOfType("object", null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void CreateWrapperOfType_NullType_ThrowsArgumentNullException() { AssertExtensions.Throws("t", () => Marshal.CreateWrapperOfType("object", null)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/DestroyStructureTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/DestroyStructureTests.cs index f9f422105b5ab..17a737da4145b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/DestroyStructureTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/DestroyStructureTests.cs @@ -84,10 +84,13 @@ public static IEnumerable DestroyStructure_InvalidType_TestData() yield return new object[] { typeof(GenericClass<>).GetTypeInfo().GenericTypeParameters[0] }; - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - yield return new object[] { typeBuilder }; + if (PlatformDetection.IsReflectionEmitSupported) + { + AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); + ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); + TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); + yield return new object[] { typeBuilder }; + } } [Theory] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/FinalReleaseComObjectTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/FinalReleaseComObjectTests.Windows.cs index 696d013712f87..dbac975a0b99c 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/FinalReleaseComObjectTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/FinalReleaseComObjectTests.Windows.cs @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices.Tests { public partial class FinalReleaseComObjectTests { - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void FinalReleaseComObject_ValidComObject_Success() { var comObject = new ComImportObject(); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/FinalReleaseComObjectTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/FinalReleaseComObjectTests.cs index 68d3329f38668..5d3ca90a4d3c9 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/FinalReleaseComObjectTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/FinalReleaseComObjectTests.cs @@ -14,15 +14,13 @@ public void FinalReleaseComObject_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.FinalReleaseComObject(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void FinalReleaseComObject_NullObject_ThrowsArgumentNullException() { AssertExtensions.Throws("o", () => Marshal.FinalReleaseComObject(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void FinalReleaseComObject_NonComObject_ThrowsArgumentException() { AssertExtensions.Throws("o", () => Marshal.FinalReleaseComObject(10)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.Windows.cs index 747ea33bac65d..c960cbb4d544d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.Windows.cs @@ -8,10 +8,16 @@ namespace System.Runtime.InteropServices.Tests { public partial class GenerateGuidForTypeTests { + private const string GuidStr = "708DDB5E-09B1-4550-A5D9-9D7DE2771C10"; + + [ComImport] + [Guid(GuidStr)] + private class DummyObject { } + [Fact] public void GenerateGuidForType_ComObject_ReturnsComGuid() { - Assert.Equal(new Guid("927971f5-0939-11d1-8be1-00c04fd8d503"), Marshal.GenerateGuidForType(typeof(ComImportObject))); + Assert.Equal(new Guid(GuidStr), Marshal.GenerateGuidForType(typeof(DummyObject))); } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.cs index bb3546830a53a..0e06d9c1adaef 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.cs @@ -34,11 +34,14 @@ public static IEnumerable GenerateGuidForType_Valid_TestData() yield return new object[] { typeof(ClassWithGuidAttribute) }; - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - Type collectibleType = typeBuilder.CreateType(); - yield return new object[] { collectibleType }; + if (PlatformDetection.IsReflectionEmitSupported) + { + AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); + ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); + TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); + Type collectibleType = typeBuilder.CreateType(); + yield return new object[] { collectibleType }; + } } [Theory] @@ -72,7 +75,7 @@ public void GenerateGuidForType_NullType_ThrowsArgumentNullException() AssertExtensions.Throws("type", () => Marshal.GenerateGuidForType(null)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] public void GenerateGuidForType_NotRuntimeType_ThrowsArgumentException() { AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateProgIdForTypeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateProgIdForTypeTests.cs index 8a594db904c60..6d8af136380b5 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateProgIdForTypeTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateProgIdForTypeTests.cs @@ -21,7 +21,7 @@ public static IEnumerable GenerateProgIdForType_Valid_TestData() yield return new object[] { typeof(ClassWithNullProgID), "" }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GenerateProgIdForType_Valid_TestData))] public void GenerateProgIdForType_ValidType_ReturnsExpected(Type type, string expected) { @@ -40,7 +40,7 @@ public class ClassWithNullProgID { } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GenerateProgIdForType_NullType_ThrowsArgumentNullException() { AssertExtensions.Throws("type", () => Marshal.GenerateProgIdForType(null)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComInterfaceForObjectTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComInterfaceForObjectTests.cs index 72be3c99afb56..3bf71d145906d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComInterfaceForObjectTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComInterfaceForObjectTests.cs @@ -11,8 +11,7 @@ namespace System.Runtime.InteropServices.Tests { public partial class GetComInterfaceForObjectTests { - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComInterfaceForObject_GenericWithValidClass_ReturnsExpected() { var o = new ClassWithInterface(); @@ -27,8 +26,7 @@ public void GetComInterfaceForObject_GenericWithValidClass_ReturnsExpected() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComInterfaceForObject_GenericWithValidStruct_ReturnsExpected() { var o = new StructWithInterface(); @@ -43,8 +41,7 @@ public void GetComInterfaceForObject_GenericWithValidStruct_ReturnsExpected() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComInterfaceForObject_NonGenericWithValidClass_ReturnsExpected() { var o = new ClassWithInterface(); @@ -59,8 +56,7 @@ public void GetComInterfaceForObject_NonGenericWithValidClass_ReturnsExpected() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComInterfaceForObject_NonGenericWithValidStruct_ReturnsExpected() { var o = new StructWithInterface(); @@ -75,12 +71,11 @@ public void GetComInterfaceForObject_NonGenericWithValidStruct_ReturnsExpected() } } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData(CustomQueryInterfaceMode.Allow)] [InlineData(CustomQueryInterfaceMode.Ignore)] [InlineData(CustomQueryInterfaceMode.Allow + 1)] [InlineData(CustomQueryInterfaceMode.Ignore - 1)] - [PlatformSpecific(TestPlatforms.Windows)] public void GetComInterfaceForObject_NonGenericCustomQueryInterfaceModeWithValidClass_ReturnsExpected(CustomQueryInterfaceMode mode) { var o = new ClassWithInterface(); @@ -95,12 +90,11 @@ public void GetComInterfaceForObject_NonGenericCustomQueryInterfaceModeWithValid } } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData(CustomQueryInterfaceMode.Allow)] [InlineData(CustomQueryInterfaceMode.Ignore)] [InlineData(CustomQueryInterfaceMode.Allow + 1)] [InlineData(CustomQueryInterfaceMode.Ignore - 1)] - [PlatformSpecific(TestPlatforms.Windows)] public void GetComInterfaceForObject_NonGenericCustomQueryInterfaceModeWithValidStruct_ReturnsExpected(CustomQueryInterfaceMode mode) { var o = new StructWithInterface(); @@ -127,8 +121,7 @@ public void GetComInterfaceForObject_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetComInterfaceForObject(1)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComInterfaceForObject_NullObject_ThrowsArgumentNullException() { AssertExtensions.Throws("o", () => Marshal.GetComInterfaceForObject(null, typeof(INonGenericInterface))); @@ -136,8 +129,7 @@ public void GetComInterfaceForObject_NullObject_ThrowsArgumentNullException() AssertExtensions.Throws("o", () => Marshal.GetComInterfaceForObject(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComInterfaceForObject_NullType_ThrowsArgumentNullException() { AssertExtensions.Throws("T", () => Marshal.GetComInterfaceForObject(new object(), null)); @@ -162,25 +154,27 @@ public static IEnumerable GetComInterfaceForObject_InvalidType_TestDat yield return new object[] { typeof(GenericClass<>).GetTypeInfo().GenericTypeParameters[0] }; - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - yield return new object[] { typeBuilder }; - yield return new object[] { typeof(NonComVisibleClass) }; yield return new object[] { typeof(NonComVisibleStruct) }; yield return new object[] { typeof(INonComVisibleInterface) }; - AssemblyBuilder collectibleAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); - ModuleBuilder collectibleModuleBuilder = collectibleAssemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder collectibleTypeBuilder = collectibleModuleBuilder.DefineType("Type", TypeAttributes.Interface | TypeAttributes.Abstract); - Type collectibleType = collectibleTypeBuilder.CreateType(); - yield return new object[] { collectibleType }; + if (PlatformDetection.IsReflectionEmitSupported) + { + AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); + ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); + TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); + yield return new object[] { typeBuilder }; + + AssemblyBuilder collectibleAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); + ModuleBuilder collectibleModuleBuilder = collectibleAssemblyBuilder.DefineDynamicModule("Module"); + TypeBuilder collectibleTypeBuilder = collectibleModuleBuilder.DefineType("Type", TypeAttributes.Interface | TypeAttributes.Abstract); + Type collectibleType = collectibleTypeBuilder.CreateType(); + yield return new object[] { collectibleType }; + } } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetComInterfaceForObject_InvalidType_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetComInterfaceForObject_InvalidType_ThrowsArgumentException(Type type) { AssertExtensions.Throws("t", () => Marshal.GetComInterfaceForObject(new object(), type)); @@ -193,9 +187,8 @@ public static IEnumerable GetComInterfaceForObject_InvalidObject_TestD yield return new object[] { new GenericStruct() }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetComInterfaceForObject_InvalidObject_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetComInterfaceForObject_InvalidObject_ThrowsArgumentException(object o) { AssertExtensions.Throws("o", () => Marshal.GetComInterfaceForObject(o, typeof(INonGenericInterface))); @@ -203,8 +196,7 @@ public void GetComInterfaceForObject_InvalidObject_ThrowsArgumentException(objec AssertExtensions.Throws("o", () => Marshal.GetComInterfaceForObject(o)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetTypedObjectForIUnknown_UncastableType_ThrowsInvalidCastException() { Assert.Throws(() => Marshal.GetComInterfaceForObject(new object(), typeof(INonGenericInterface))); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.Windows.cs index 17a4bcc797941..3de824b13882f 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.Windows.cs @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices.Tests { public partial class GetComObjectDataTests { - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComObjectData_ValidObject_ReturnsExpected() { var comObject = new ComImportObject(); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.cs index 4cdf04d7f0a01..813faf61a9df4 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.cs @@ -15,22 +15,19 @@ public void GetComObjectData_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetComObjectData(null, null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComObjectData_NullObj_ThrowsArgumentNullException() { AssertExtensions.Throws("obj", () => Marshal.GetComObjectData(null, new object())); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComObjectData_NullKey_ThrowsArgumentNullException() { AssertExtensions.Throws("key", () => Marshal.GetComObjectData(new object(), null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetComObjectData_NonComObjectObj_ThrowsArgumentNullException() { AssertExtensions.Throws("obj", () => Marshal.GetComObjectData(1, 2)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetDelegateForFunctionPointerTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetDelegateForFunctionPointerTests.cs index c52dd8d9b9632..abcf514822786 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetDelegateForFunctionPointerTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetDelegateForFunctionPointerTests.cs @@ -28,7 +28,7 @@ public void GetDelegateForFunctionPointer_NonGeneric_ReturnsExpected(Type t) VerifyDelegate(functionDelegate, targetMethod); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] public void GetDelegateForFunctionPointer_CollectibleType_ReturnsExpected() { MethodInfo targetMethod = typeof(GetDelegateForFunctionPointerTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static); @@ -122,10 +122,13 @@ public static IEnumerable GetDelegateForFunctionPointer_InvalidType_Te yield return new object[] { typeof(GenericClass<>).GetTypeInfo().GenericTypeParameters[0] }; - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - yield return new object[] { typeBuilder }; + if (PlatformDetection.IsReflectionEmitSupported) + { + AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); + ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); + TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); + yield return new object[] { typeBuilder }; + } yield return new object[] { typeof(Delegate) }; yield return new object[] { typeof(GenericDelegate<>) }; diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetEndComSlotTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetEndComSlotTests.Windows.cs index 457f032eacf1c..baf55a00da2d5 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetEndComSlotTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetEndComSlotTests.Windows.cs @@ -24,8 +24,8 @@ public static IEnumerable GetEndComSlot_TestData() yield return new object[] { typeof(ManagedAutoDualClass), 10 }; } + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetEndComSlot_TestData))] - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] public void GetEndComSlot_Windows_ReturnsExpected(Type type, int expected) { Assert.Equal(expected, Marshal.GetEndComSlot(type)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetEndComSlotTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetEndComSlotTests.cs index 7f33a060cc9a4..08962f1a9b07c 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetEndComSlotTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetEndComSlotTests.cs @@ -18,15 +18,13 @@ public void GetEndComSlot_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetEndComSlot(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetEndComSlot_NullType_ThrowsArgumentNullException() { AssertExtensions.Throws(null, () => Marshal.GetEndComSlot(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled), nameof(PlatformDetection.IsReflectionEmitSupported))] public void GetEndComSlot_NotRuntimeType_ThrowsArgumentException() { AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); @@ -41,9 +39,8 @@ public static IEnumerable GetStartComSlot_InvalidGenericType_TestData( yield return new object[] { typeof(GenericClass<>).GetTypeInfo().GenericTypeParameters[0] }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetStartComSlot_InvalidGenericType_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetEndComSlot_InvalidGenericType_ThrowsArgumentNullException(Type type) { AssertExtensions.Throws(null, () => Marshal.GetEndComSlot(type)); @@ -63,16 +60,18 @@ public static IEnumerable GetStartComSlot_NotComVisibleType_TestData() yield return new object[] { typeof(int[][]) }; yield return new object[] { typeof(int[,]) }; - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - Type collectibleType = typeBuilder.CreateType(); - yield return new object[] { collectibleType }; + if (PlatformDetection.IsReflectionEmitSupported) + { + AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); + ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); + TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); + Type collectibleType = typeBuilder.CreateType(); + yield return new object[] { collectibleType }; + } } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetStartComSlot_NotComVisibleType_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetEndComSlot_NotComVisibleType_ThrowsArgumentException(Type type) { AssertExtensions.Throws("t", () => Marshal.GetEndComSlot(type)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetExceptionCodeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetExceptionCodeTests.cs index 75b00616c488b..098a246313f2c 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetExceptionCodeTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetExceptionCodeTests.cs @@ -36,7 +36,7 @@ public void GetExceptionCode_NormalExceptionInsideCatch_ReturnsExpected(int hres Assert.Equal(0, Marshal.GetExceptionCode()); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))] [InlineData(-1)] [InlineData(10)] public void GetExceptionCode_ComExceptionInsideCatch_ReturnsExpected(int errorCode) diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetHINSTANCETests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetHINSTANCETests.cs index deb55c3ef4195..f84a47a48bef2 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetHINSTANCETests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetHINSTANCETests.cs @@ -17,7 +17,7 @@ public void GetHINSTANCE_NormalModule_ReturnsSameInstance() Assert.Equal(ptr, Marshal.GetHINSTANCE(typeof(string).Module)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] public void GetHINSTANCE_ModuleBuilder_ReturnsSameInstance() { AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.Windows.cs index ac109e89eff0f..8ad00b8e31081 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.Windows.cs @@ -27,7 +27,7 @@ public static IEnumerable GetIDispatchForObject_ComObject_TestData() yield return new object[] { new AutoDualComObjectEmpty() }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetIDispatchForObject_ComObject_TestData))] public void GetIDispatchForObject_DispatchObject_Success(object obj) { @@ -42,7 +42,7 @@ public void GetIDispatchForObject_DispatchObject_Success(object obj) } } - [ConditionalFact(typeof(PlatformDetection), nameof (PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetIDispatchForObject_ManagedIInspectableObject_Fail() { Assert.Throws(() => Marshal.GetIDispatchForObject(new IInspectableManagedObject())); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.cs index a32b6799c23f1..c5588d1a01ca8 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.cs @@ -18,15 +18,13 @@ public void GetIDispatchForObject_NetCore_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetIDispatchForObject(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetIDispatchForObject_NullObject_ThrowsArgumentNullException() { AssertExtensions.Throws("o", () => Marshal.GetIDispatchForObject(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetIDispatchForObject_NonDispatchObject_ThrowsInvalidCastException() { Assert.Throws(() => Marshal.GetIDispatchForObject(string.Empty)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIUnknownForObjectTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIUnknownForObjectTests.cs index 88fd8ee343d76..1b9bb152ad98f 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIUnknownForObjectTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIUnknownForObjectTests.cs @@ -16,8 +16,7 @@ public void GetIUnknownForObject_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetIUnknownForObject(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetIUnknownForObject_NullObject_ThrowsArgumentNullException() { AssertExtensions.Throws("o", () => Marshal.GetIUnknownForObject(null)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.Windows.cs index c6b9528b8f387..ea466ac7d3176 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.Windows.cs @@ -43,14 +43,14 @@ public static IEnumerable GetNativeVariantForObject_ComObjectArray_Tes yield return new object[] { new AutoDualComObjectEmpty[] { autoDualEmpty, null }, (VarEnum.VT_ARRAY | VarEnum.VT_UNKNOWN), new object[] { autoDualEmpty, null } }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetNativeVariantForObject_ComObjectArray_TestData))] public void GetNativeVariantForObject_ComObjectArray_Success(object obj, VarEnum expectedVarType, object expectedRoundtripValue) { GetNativeVariantForObject_ValidObject_Success(obj, expectedVarType, (IntPtr)(-1), expectedRoundtripValue); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetNativeVariantForObject_ComObject_TestData))] public void GetNativeVariantForObject_ComObject_Success(object obj, VarEnum expectedVarType) { @@ -87,7 +87,7 @@ public static IEnumerable GetNativeVariantForObject_WrappedComObject_T yield return new object[] { new DispatchWrapper(autoDual), autoDual, VarEnum.VT_DISPATCH }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetNativeVariantForObject_WrappedComObject_TestData))] public void GetNativeVariantForObject_WrappedComObject_Success(object obj, object wrapped, VarEnum expectedVarType) { @@ -104,7 +104,7 @@ public static IEnumerable GetNativeVariantForObject_InvalidArrayType_T yield return new object[] { new AutoDualComObject[] { new AutoDualComObject(), null } }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetNativeVariantForObject_InvalidArrayType_TestData))] public void GetNativeVariantForObject_InvalidArrayType_ThrowsInvalidCastException(object obj) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.cs index 34fee0dd1d7a2..c25c59a205c96 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.cs @@ -19,8 +19,7 @@ private void GetNativeVariantForObject_RoundtrippingPrimitives_Success(object pr GetNativeVariantForObject_ValidObject_Success(primitive, expectedVarType, expectedValue, primitive); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetNativeVariantForObject_TypeMissing_Success() { // This cannot be in the test data as XUnit uses MethodInfo.Invoke to call test methods and @@ -106,9 +105,8 @@ public static IEnumerable GetNativeVariantForObject_NonRoundtrippingPr yield return new object[] { Color.FromArgb(10), VarEnum.VT_UI4, (IntPtr)655360, (uint)655360 }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetNativeVariantForObject_NonRoundtrippingPrimitives_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetNativeVariantForObject_ValidObject_Success(object primitive, VarEnum expectedVarType, IntPtr expectedValue, object expectedRoundtripValue) { var v = new Variant(); @@ -138,10 +136,9 @@ public void GetNativeVariantForObject_ValidObject_Success(object primitive, VarE } } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData("")] [InlineData("99")] - [PlatformSpecific(TestPlatforms.Windows)] public void GetNativeVariantForObject_String_Success(string obj) { var v = new Variant(); @@ -170,9 +167,8 @@ public void GetNativeVariantForObject_String_Success(string obj) } } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData(3.14)] - [PlatformSpecific(TestPlatforms.Windows)] public unsafe void GetNativeVariantForObject_Double_Success(double obj) { var v = new Variant(); @@ -194,9 +190,8 @@ public unsafe void GetNativeVariantForObject_Double_Success(double obj) } } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData(3.14f)] - [PlatformSpecific(TestPlatforms.Windows)] public unsafe void GetNativeVariantForObject_Float_Success(float obj) { var v = new Variant(); @@ -226,8 +221,7 @@ public void GetNativeVariantForObject_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetNativeVariantForObject(1, IntPtr.Zero)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetNativeVariantForObject_ZeroPointer_ThrowsArgumentNullException() { AssertExtensions.Throws("pDstNativeVariant", () => Marshal.GetNativeVariantForObject(new object(), IntPtr.Zero)); @@ -240,17 +234,15 @@ public static IEnumerable GetNativeVariantForObject_GenericObject_Test yield return new object[] { new GenericStruct() }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetNativeVariantForObject_GenericObject_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetNativeVariantForObject_GenericObject_ThrowsArgumentException(object obj) { AssertExtensions.Throws("obj", () => Marshal.GetNativeVariantForObject(obj, (IntPtr)1)); AssertExtensions.Throws("obj", () => Marshal.GetNativeVariantForObject(obj, (IntPtr)1)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetNativeVariant_InvalidArray_ThrowsSafeArrayTypeMismatchException() { var v = new Variant(); @@ -272,9 +264,8 @@ public static IEnumerable GetNativeVariant_VariantWrapper_TestData() yield return new object[] { new VariantWrapper[] { new VariantWrapper(null) } }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetNativeVariant_VariantWrapper_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetNativeVariant_VariantWrapper_ThrowsArgumentException(object obj) { var v = new Variant(); @@ -299,9 +290,8 @@ public static IEnumerable GetNativeVariant_HandleObject_TestData() yield return new object[] { new FakeCriticalHandle[] { new FakeCriticalHandle() } }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetNativeVariant_HandleObject_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetNativeVariant_HandleObject_ThrowsArgumentException(object obj) { var v = new Variant(); @@ -317,8 +307,7 @@ public void GetNativeVariant_HandleObject_ThrowsArgumentException(object obj) } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public static void GetNativeVariantForObject_CantCastToObject_ThrowsInvalidCastException() { // While GetNativeVariantForObject supports taking chars, GetObjectForNativeVariant will diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.Windows.cs index 2641d39de0e90..1c35391fb2e7f 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.Windows.cs @@ -27,7 +27,7 @@ public static IEnumerable GetObjectForIUnknown_ComObject_TestData() yield return new object[] { new AutoDualComObjectEmpty() }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForIUnknown_ComObject_TestData))] public void GetObjectForIUnknown_ComObject_ReturnsExpected(object o) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.cs index 253f6d0960cb4..69958242da9df 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.cs @@ -34,9 +34,8 @@ public static IEnumerable GetObjectForIUnknown_Valid_TestData() yield return new object[] { new KeyValuePair("key", 10) }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForIUnknown_Valid_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForIUnknown_ValidPointer_ReturnsExpected(object o) { IntPtr ptr = Marshal.GetIUnknownForObject(o); @@ -58,8 +57,7 @@ public void GetObjectForIUnknown_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetObjectForIUnknown(IntPtr.Zero)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetObjectForIUnknown_NullPointer_ThrowsArgumentNullException() { AssertExtensions.Throws("pUnk", () => Marshal.GetObjectForIUnknown(IntPtr.Zero)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.Windows.cs index 632f36de0b3b5..b7a3b8e398e58 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.Windows.cs @@ -493,7 +493,7 @@ public static IEnumerable GetObjectForNativeVariant_TestData() }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_PrimitivesByRef_TestData))] [MemberData(nameof(GetObjectForNativeVariant_TestData))] public void GetObjectForNativeVariant_Normal_ReturnsExpected(Variant variant, object expected) @@ -508,7 +508,7 @@ public void GetObjectForNativeVariant_Normal_ReturnsExpected(Variant variant, ob } } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetObjectForNativeVariant_ErrorMissing_ReturnsTypeMissing() { // This cannot be in the [MemberData] as XUnit uses reflection to invoke the test method @@ -516,7 +516,7 @@ public void GetObjectForNativeVariant_ErrorMissing_ReturnsTypeMissing() GetObjectForNativeVariant_Normal_ReturnsExpected(CreateVariant(VT_ERROR, new UnionTypes { _error = unchecked((int)0x80020004) }), Type.Missing); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_PrimitivesByRef_TestData))] public void GetObjectForNativeVariant_NestedVariant_ReturnsExpected(Variant source, object expected) { @@ -536,7 +536,7 @@ public void GetObjectForNativeVariant_NestedVariant_ReturnsExpected(Variant sour } } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetObjectForNativeVariant_Record_Throws() { int record = 10; @@ -566,7 +566,7 @@ public void GetObjectForNativeVariant_Record_Throws() } } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_PrimitivesByRef_TestData))] public unsafe void GetObjectForNativeVariant_ByRef_ReturnsExpected(Variant source, object value) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.cs index 4da69030fdead..c0b68f5d899ec 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.cs @@ -128,9 +128,8 @@ public static IEnumerable GetObjectForNativeVariant_Decimal_TestData() yield return new object[] { -10.5m }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_Decimal_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForNativeVariant_Decimal_ReturnsExpected(decimal d) { var variant = new Variant { m_decimal = d }; @@ -138,9 +137,8 @@ public void GetObjectForNativeVariant_Decimal_ReturnsExpected(decimal d) Assert.Equal(d, GetObjectForNativeVariant(variant)); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_Decimal_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public unsafe void GetObjectForNativeVariant_DecimalByRef_Success(decimal d) { IntPtr ptr = new IntPtr(&d); @@ -157,9 +155,8 @@ public static IEnumerable GetObjectForNativeVariant_Array_TestData() }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_Array_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForNativeVariant_Array_ReturnsExpected(Variant source, object expected) { Assert.Equal(expected, GetObjectForNativeVariant(source)); @@ -173,15 +170,14 @@ public void GetObjectForNativeVariant_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetObjectForNativeVariant(IntPtr.Zero)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetObjectForNativeVariant_ZeroPointer_ThrowsArgumentNullException() { AssertExtensions.Throws("pSrcNativeVariant", () => Marshal.GetObjectForNativeVariant(IntPtr.Zero)); AssertExtensions.Throws("pSrcNativeVariant", () => Marshal.GetObjectForNativeVariant(IntPtr.Zero)); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData(VT_I1 | VT_BYREF)] [InlineData(VT_I2 | VT_BYREF)] [InlineData(VT_I4 | VT_BYREF)] @@ -228,7 +224,6 @@ public void GetObjectForNativeVariant_ZeroPointer_ThrowsArgumentNullException() [InlineData(VT_ARRAY | VT_BYREF)] [InlineData(VT_RESERVED | VT_BYREF)] [InlineData(VT_ILLEGAL | VT_BYREF)] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForNativeVariant_ZeroByRefTypeNotEmptyOrNull_ThrowsArgumentException(ushort vt) { var variant = new Variant(); @@ -238,21 +233,19 @@ public void GetObjectForNativeVariant_ZeroByRefTypeNotEmptyOrNull_ThrowsArgument AssertExtensions.Throws(null, () => GetObjectForNativeVariant(variant)); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData(-657435.0)] [InlineData(2958466.0)] [InlineData(double.NegativeInfinity)] [InlineData(double.PositiveInfinity)] [InlineData(double.NaN)] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForNativeVariant_InvalidDate_ThrowsArgumentException(double value) { Variant variant = CreateVariant(VT_DATE, new UnionTypes { _date = value }); AssertExtensions.Throws(null, () => GetObjectForNativeVariant(variant)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetObjectForNativeVariant_NoDataForRecord_ThrowsArgumentException() { Variant variant = CreateVariant(VT_RECORD, new UnionTypes { _record = new Record { _recordInfo = IntPtr.Zero } }); @@ -265,9 +258,8 @@ public static IEnumerable GetObjectForNativeVariant_NoSuchGuid_TestDat yield return new object[] { Guid.Empty }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_NoSuchGuid_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForNativeVariant_NoSuchGuid_ThrowsArgumentException(Guid guid) { int record = 10; @@ -329,17 +321,15 @@ public static IEnumerable GetObjectForNativeVariant_CantMap_ThrowsArgu yield return new object[] { CreateVariant(127, new UnionTypes()) }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_CantMap_ThrowsArgumentException_Data))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForNativeVariant_CantMap_ThrowsArgumentException(Variant variant) { AssertExtensions.Throws(null, () => GetObjectForNativeVariant(variant)); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_CantMap_ThrowsArgumentException_Data))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForNativeVariant_CantMapByRef_ThrowsArgumentException(Variant variant) { variant.m_Variant.vt |= VT_BYREF; @@ -362,26 +352,23 @@ public static IEnumerable GetObjectForNativeVariant_InvalidVarType_Tes yield return new object[] { VT_ILLEGAL }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_InvalidVarType_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForNativeVariant_InvalidVarType_InvalidOleVariantTypeException(ushort vt) { Variant variant = CreateVariant(vt, new UnionTypes { _byref = (IntPtr)10 }); Assert.Throws(() => GetObjectForNativeVariant(variant)); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetObjectForNativeVariant_InvalidVarType_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetObjectForNativeVariant_InvalidVarTypeByRef_InvalidOleVariantTypeException(ushort vt) { Variant variant = CreateVariant((ushort)(vt | VT_BYREF), new UnionTypes { _byref = (IntPtr)10 }); Assert.Throws(() => GetObjectForNativeVariant(variant)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetObjectForNativeVariant_ByRefNestedVariant_InvalidOleVariantTypeException() { var source = new Variant(); @@ -406,8 +393,7 @@ public void GetObjectForNativeVariant_ByRefNestedVariant_InvalidOleVariantTypeEx } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetObjectForNativeVariant_ArrayOfEmpty_ThrowsInvalidOleVariantTypeException() { Variant variant = CreateVariant(VT_ARRAY, new UnionTypes { _parray = (IntPtr)10 }); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectsForNativeVariantsTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectsForNativeVariantsTests.cs index 977cfa020f2f0..9232818ce04bf 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectsForNativeVariantsTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectsForNativeVariantsTests.cs @@ -56,8 +56,7 @@ internal struct Variant [FieldOffset(0)] public decimal m_decimal; } #pragma warning disable 618 - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void SByteType() { Variant v = new Variant(); @@ -78,8 +77,7 @@ public void SByteType() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void ByteType() { Variant v = new Variant(); @@ -100,8 +98,7 @@ public void ByteType() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void DoubleType() { Variant v = new Variant(); @@ -122,8 +119,7 @@ public void DoubleType() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void ShortType() { Variant v = new Variant(); @@ -144,8 +140,7 @@ public void ShortType() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void UshortType() { Variant v = new Variant(); @@ -166,8 +161,7 @@ public void UshortType() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void IntType() { Variant v = new Variant(); @@ -188,8 +182,7 @@ public void IntType() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void UIntType() { Variant v = new Variant(); @@ -210,8 +203,7 @@ public void UIntType() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void LongType() { Variant v = new Variant(); @@ -232,8 +224,7 @@ public void LongType() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void ULongType() { Variant v = new Variant(); @@ -254,8 +245,7 @@ public void ULongType() } } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void FloatType() { Variant v = new Variant(); @@ -284,16 +274,14 @@ public static void GetObjectsForNativeVariants_Unix_ThrowsPlatformNotSupportedEx Assert.Throws(() => Marshal.GetObjectsForNativeVariants(IntPtr.Zero, 10)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public static void GetObjectsForNativeVariants_ZeroPointer_ThrowsArgumentNullException() { AssertExtensions.Throws("aSrcNativeVariant", () => Marshal.GetObjectsForNativeVariants(IntPtr.Zero, 10)); AssertExtensions.Throws("aSrcNativeVariant", () => Marshal.GetObjectsForNativeVariants(IntPtr.Zero, 10)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public static void GetObjectsForNativeVariants_NegativeCount_ThrowsArgumentOutOfRangeException() { AssertExtensions.Throws("cVars", () => Marshal.GetObjectsForNativeVariants((IntPtr)1, -1)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.Windows.cs index 68552be972fd5..30a0d0d4884fb 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.Windows.cs @@ -14,7 +14,7 @@ public static IEnumerable GetStartComSlot_TestData() yield return new object[] { typeof(ComImportObject), -1 }; yield return new object[] { typeof(SubComImportObject), -1 }; yield return new object[] { typeof(InterfaceComImportObject), -1 }; - yield return new object[] { typeof(InterfaceAndComImportObject), 7 }; + yield return new object[] { typeof(InterfaceOnComImportObject), 7 }; yield return new object[] { typeof(IComImportObject), 7 }; yield return new object[] { typeof(DualInterface), 7}; @@ -39,15 +39,15 @@ public static IEnumerable GetStartComSlot_TestData() yield return new object[] { typeof(ManagedAutoDualClass), 7 }; } + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetStartComSlot_TestData))] - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] public void GetStartComSlot_Windows_ReturnsExpected(Type type, int expected) { Assert.Equal(expected, Marshal.GetStartComSlot(type)); } - [ConditionalFact(typeof(PlatformDetection), nameof (PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetStartComSlot_ManagedIInspectableObject_Fail() { Assert.Throws(() => Marshal.GetStartComSlot(typeof(IInspectableInterface))); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.cs index a7f78a0d6223a..26563c085e059 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.cs @@ -18,15 +18,13 @@ public void GetStartComSlot_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetStartComSlot(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetStartComSlot_NullType_ThrowsArgumentNullException() { AssertExtensions.Throws(null, () => Marshal.GetStartComSlot(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetStartComSlot_NotRuntimeType_ThrowsArgumentException() { AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); @@ -41,9 +39,8 @@ public static IEnumerable GetStartComSlot_InvalidGenericType_TestData( yield return new object[] { typeof(GenericClass<>).GetTypeInfo().GenericTypeParameters[0] }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetStartComSlot_InvalidGenericType_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetStartComSlot_InvalidGenericType_ThrowsArgumentNullException(Type type) { AssertExtensions.Throws(null, () => Marshal.GetStartComSlot(type)); @@ -70,9 +67,8 @@ public static IEnumerable GetStartComSlot_NotComVisibleType_TestData() yield return new object[] { collectibleType }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetStartComSlot_NotComVisibleType_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetStartComSlot_NotComVisibleType_ThrowsArgumentException(Type type) { AssertExtensions.Throws("t", () => Marshal.GetStartComSlot(type)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeFromCLSIDTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeFromCLSIDTests.cs index e25683e8492b5..d0f0a1533c755 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeFromCLSIDTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeFromCLSIDTests.cs @@ -8,13 +8,17 @@ namespace System.Runtime.InteropServices.Tests { public class GetTypeFromCLSIDTests { - private static readonly Guid TestCLSID = new Guid("927971f5-0939-11d1-8be1-00c04fd8d503"); + // Represents a COM server that exists on all Windows skus that support IDispatch. + // See System.DirectoryServices.AccountManagement.ADsLargeInteger. + private const string IDispatchSupportedComServer = "927971f5-0939-11d1-8be1-00c04fd8d503"; + private const string IDispatchSupportedComServerProgId = "LargeInteger"; - private const string TestProgID = "LargeInteger"; + private static readonly Guid TestCLSID = new Guid(IDispatchSupportedComServer); + + private const string TestProgID = IDispatchSupportedComServerProgId; private const string TestServerName = "____NonExistingServer____"; - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetTypeFromCLSID_NoSuchCLSIDExists_ReturnsExpected() { Type type = Marshal.GetTypeFromCLSID(Guid.Empty); @@ -27,8 +31,7 @@ public void GetTypeFromCLSID_NoSuchCLSIDExists_ReturnsExpected() Assert.Throws(() => Activator.CreateInstance(type)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport))] public void GetTypeFromCLSID_CLSIDExists_ReturnsExpected() { Type type = Marshal.GetTypeFromCLSID(TestCLSID); @@ -46,8 +49,7 @@ public void GetTypeFromCLSID_CLSIDExists_ReturnsExpected() Assert.NotNull(Activator.CreateInstance(type)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport))] public void GetTypeFromCLSID_CLSIDExists_Server_ReturnsExpected() { Type type = Type.GetTypeFromCLSID(TestCLSID, server: TestServerName, throwOnError: true); @@ -74,7 +76,7 @@ public void GetTypeFromProgID_Unix() Assert.Throws(() => Type.GetTypeFromProgID(TestProgID, throwOnError: true)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetTypeFromProgID_ReturnsExpected() { AssertExtensions.Throws("progID", () => Type.GetTypeFromProgID(null)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeInfoNameTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeInfoNameTests.cs index b8a2986a1ecd7..b2b601a4f65c1 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeInfoNameTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeInfoNameTests.cs @@ -10,8 +10,7 @@ namespace System.Runtime.InteropServices.Tests { public class GetTypeInfoNameTests { - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetTypeInfoName_ValidTypeInfo_ReturnsExpected() { Assert.Equal("strName", Marshal.GetTypeInfoName(new TypeInfo())); @@ -24,8 +23,7 @@ public void GetTypeInfoName_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetTypeInfoName((ITypeInfo)null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetTypeInfoName_NullTypeInfo_ThrowsArgumentNullException() { AssertExtensions.Throws("typeInfo", () => Marshal.GetTypeInfoName((ITypeInfo)null)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypedObjectForIUnknownTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypedObjectForIUnknownTests.Windows.cs index 044bc52900666..8a9d82a466901 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypedObjectForIUnknownTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypedObjectForIUnknownTests.Windows.cs @@ -33,7 +33,7 @@ public static IEnumerable GetTypedObjectForIUnknown_ComObject_TestData yield return new object[] { new AutoDualComObjectEmpty(), typeof(AutoDualComObjectEmpty) }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetTypedObjectForIUnknown_ComObject_TestData))] public void GetTypedObjectForIUnknown_ComObject_ReturnsExpected(object o, Type type) { @@ -46,7 +46,7 @@ public static IEnumerable GetTypedObjectForIUnknownTypeUncastableComOb yield return new object[] { new IInspectableComObject(), typeof(IUnknownInterface) }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetTypedObjectForIUnknownTypeUncastableComObject_TestData))] public void GetTypedObjectForIUnknown_UncastableComObject_ThrowsInvalidCastException(object o, Type type) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypedObjectForIUnknownTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypedObjectForIUnknownTests.cs index d62112a09ba05..c68c6fcc7b012 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypedObjectForIUnknownTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypedObjectForIUnknownTests.cs @@ -63,9 +63,8 @@ public static IEnumerable GetTypedObjectForIUnknown_TestData() yield return new object[] { new KeyValuePair("key", 10), typeof(ValueType) }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetTypedObjectForIUnknown_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetTypedObjectForIUnknown_ValidPointer_ReturnsExpected(object o, Type type) { IntPtr ptr = Marshal.GetIUnknownForObject(o); @@ -86,15 +85,13 @@ public void GetTypedObjectForIUnknown_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.GetTypedObjectForIUnknown(IntPtr.Zero, typeof(int))); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetTypedObjectForIUnknown_ZeroUnknown_ThrowsArgumentNullException() { AssertExtensions.Throws("pUnk", () => Marshal.GetTypedObjectForIUnknown(IntPtr.Zero, typeof(int))); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetTypedObjectForIUnknown_NullType_ThrowsArgumentNullException() { IntPtr iUnknown = Marshal.GetIUnknownForObject(new object()); @@ -122,9 +119,8 @@ public static IEnumerable GetTypedObjectForIUnknown_Invalid_TestData() yield return new object[] { typeBuilder }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetTypedObjectForIUnknown_Invalid_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetTypedObjectForIUnknown_InvalidType_ThrowsArgumentException(Type type) { IntPtr ptr = Marshal.GetIUnknownForObject(new object()); @@ -158,9 +154,8 @@ public static IEnumerable GetTypedObjectForIUnknownType_UncastableObje yield return new object[] { new object(), collectibleType }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetTypedObjectForIUnknownType_UncastableObject_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetTypedObjectForIUnknown_UncastableObject_ThrowsInvalidCastException(object o, Type type) { IntPtr ptr = Marshal.GetIUnknownForObject(o); @@ -181,9 +176,8 @@ public static IEnumerable GetTypedObjectForIUnknown_ArrayObjects_TestD yield return new object[] { new int[,] { { 10 } } }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetTypedObjectForIUnknown_ArrayObjects_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetTypedObjectForIUnknown_ArrayType_ThrowsBadImageFormatException(object o) { IntPtr ptr = Marshal.GetIUnknownForObject(o); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetUniqueObjectForIUnknownTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetUniqueObjectForIUnknownTests.Windows.cs index 03b3d239564d1..9aec62ff807b8 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetUniqueObjectForIUnknownTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetUniqueObjectForIUnknownTests.Windows.cs @@ -27,7 +27,7 @@ public static IEnumerable GetUniqueObjectForIUnknown_ComObject_TestDat yield return new object[] { new AutoDualComObjectEmpty() }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetUniqueObjectForIUnknown_ComObject_TestData))] public void GetUniqueObjectForIUnknown_ComObject_ReturnsExpected(object o) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetUniqueObjectForIUnknownTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetUniqueObjectForIUnknownTests.cs index 6a3ac5e5ad13e..a1d221c1d5051 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetUniqueObjectForIUnknownTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetUniqueObjectForIUnknownTests.cs @@ -34,9 +34,8 @@ public static IEnumerable GetUniqueObjectForIUnknown_Valid_TestData() yield return new object[] { new KeyValuePair("key", 10) }; } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(GetUniqueObjectForIUnknown_Valid_TestData))] - [PlatformSpecific(TestPlatforms.Windows)] public void GetUniqueObjectForIUnknown_ValidPointer_ReturnsExpected(object o) { IntPtr ptr = Marshal.GetIUnknownForObject(o); @@ -58,8 +57,7 @@ public void GetUniqueObjectForIUnknown_Unix_ThrowsPlatformNotSupportedException( Assert.Throws(() => Marshal.GetUniqueObjectForIUnknown(IntPtr.Zero)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetUniqueObjectForIUnknown_NullPointer_ThrowsArgumentNullException() { AssertExtensions.Throws("unknown", () => Marshal.GetUniqueObjectForIUnknown(IntPtr.Zero)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.Windows.cs index 221611f5a45a4..a7e3f4442d3b8 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.Windows.cs @@ -15,11 +15,11 @@ public static IEnumerable IsComObject_Windows_TestData() yield return new object[] { new ComImportObject[0], false }; yield return new object[] { new SubComImportObject(), true }; yield return new object[] { new GenericSubComImportObject(), true }; - yield return new object[] { new InterfaceAndComImportObject(), true }; + yield return new object[] { new InterfaceOnComImportObject(), true }; yield return new object[] { new InterfaceComImportObject(), false }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(IsComObject_Windows_TestData))] public void IsComObject_Windows_ReturnsExpected(object value, bool expected) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.cs index 9aa029e8ea86e..97a2730e2762f 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.cs @@ -53,7 +53,7 @@ public static IEnumerable IsComObject_TestData() yield return new object[] { collectibleComImportObject }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(IsComObject_TestData))] public void IsComObject_NonComObject_ReturnsFalse(object value) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsTypeVisibleFromComTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsTypeVisibleFromComTests.Windows.cs index a28d9f1323c09..81153ea54e41a 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsTypeVisibleFromComTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsTypeVisibleFromComTests.Windows.cs @@ -12,7 +12,7 @@ public partial class IsTypeVisibleFromComTests public static IEnumerable IsTypeVisibleFromCom_Windows_TestData() { yield return new object[] { typeof(ComImportObject), true }; - yield return new object[] { typeof(InterfaceAndComImportObject), true }; + yield return new object[] { typeof(InterfaceOnComImportObject), true }; yield return new object[] { typeof(InterfaceComImportObject), true }; yield return new object[] { typeof(IsTypeVisibleFromComTests), true }; @@ -26,7 +26,7 @@ public static IEnumerable IsTypeVisibleFromCom_Windows_TestData() yield return new object[] { typeof(ManagedClassWithComVisibleTrue), true }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(IsTypeVisibleFromCom_Windows_TestData))] public void IsTypeVisibleFromCom_Windows_ReturnsExpected(Type value, bool expected) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/PtrToStructureTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/PtrToStructureTests.cs index c9c50f15f8c36..f2a13cc142a8c 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/PtrToStructureTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/PtrToStructureTests.cs @@ -220,7 +220,7 @@ public void PtrToStructure_GenericType_ThrowsArgumentException(Type structureTyp AssertExtensions.Throws("structureType", () => Marshal.PtrToStructure((IntPtr)1, structureType)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] public void PtrToStructure_NonRuntimeType_ThrowsArgumentException() { AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs index 74ffdaad3b2db..12f1a69a4e912 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs @@ -37,12 +37,9 @@ public static IEnumerable QueryInterface_ValidComObjectInterface_TestD yield return new object[] { new AutoDispatchComObjectEmpty(), IID_IDISPATCH }; yield return new object[] { new AutoDualComObjectEmpty(), IID_IUNKNOWN }; yield return new object[] { new AutoDualComObjectEmpty(), IID_IDISPATCH }; - - yield return new object[] { new IUnknownComObject(), IID_IUNKNOWN }; - yield return new object[] { new IUnknownComObject(), IID_IDISPATCH }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(QueryInterface_ValidComObjectInterface_TestData))] public void QueryInterface_ValidComObjectInterface_Success(object o, string iidString) { @@ -69,7 +66,7 @@ public void QueryInterface_ValidComObjectInterface_Success(object o, string iidS public static IEnumerable QueryInterface_NoSuchComObjectInterface_TestData() { - const string IID_CUSTOMINTERFACE = "927971f5-0939-11d1-8be1-00c04fd8d503"; + const string IID_CUSTOMINTERFACE = "ED53244F-0514-49D1-9A85-E14B33E71CDF"; yield return new object[] { new ComImportObject(), IID_IINSPECTABLE }; yield return new object[] { new ComImportObject(), IID_CUSTOMINTERFACE }; @@ -98,7 +95,7 @@ public static IEnumerable QueryInterface_NoSuchComObjectInterface_Test yield return new object[] { new AutoDualComObjectEmpty(), IID_CUSTOMINTERFACE }; } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [MemberData(nameof(QueryInterface_NoSuchComObjectInterface_TestData))] public void QueryInterface_NoSuchComObjectInterface_Success(object o, string iidString) { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.cs index a52f710abf576..7d1db477dd974 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.cs @@ -49,7 +49,7 @@ public void QueryInterface_ValidInterface_Success(object o, string iidString) public static IEnumerable QueryInterface_NoSuchInterface_TestData() { yield return new object[] { new object(), Guid.Empty.ToString() }; - yield return new object[] { new object(), "927971f5-0939-11d1-8be1-00c04fd8d503" }; + yield return new object[] { new object(), "639610C8-26EA-48BB-BD74-4BC18EECC6EA" }; } [Theory] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/ByteTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/ByteTests.cs index 8e43f243549cf..2d9a9c4977f4c 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/ByteTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/ByteTests.cs @@ -145,7 +145,7 @@ public void ReadByte_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.ReadByte(null, 2)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadByte_NotReadable_ThrowsArgumentException() { @@ -173,7 +173,7 @@ public void WriteByte_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.WriteByte(null, 2, 0)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.WriteByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteByte_NotReadable_ThrowsArgumentException() { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int16Tests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int16Tests.cs index 2a2bd34466167..da886307dddd1 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int16Tests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int16Tests.cs @@ -140,7 +140,7 @@ public void ReadInt16_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.ReadInt16(null, 2)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.ReadInt16 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadInt16_NotReadable_ThrowsArgumentException() { @@ -168,7 +168,7 @@ public void WriteInt16_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.WriteInt16(null, 2, 0)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.WriteInt16 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteInt16_NotReadable_ThrowsArgumentException() { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int32Tests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int32Tests.cs index cddfa7d7ecd77..276dca25e110a 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int32Tests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int32Tests.cs @@ -142,7 +142,7 @@ public void ReadInt32_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.ReadInt32(null, 2)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.ReadInt32 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadInt32_NotReadable_ThrowsArgumentException() { @@ -170,7 +170,7 @@ public void WriteInt32_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.WriteInt32(null, 2, 0)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.WriteInt32 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteInt32_NotReadable_ThrowsArgumentException() { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int64Tests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int64Tests.cs index 2a389bbb64bb6..47f668270b80e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int64Tests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int64Tests.cs @@ -154,7 +154,7 @@ public void ReadInt64_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.ReadInt64(null, 2)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.ReadInt64 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadInt64_NotReadable_ThrowsArgumentException() { @@ -182,7 +182,7 @@ public void WriteInt64_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.WriteInt64(null, 2, 0)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.WriteInt64 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteInt64_NotReadable_ThrowsArgumentException() { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/IntPtrTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/IntPtrTests.cs index ae33216e35112..e6a21fce1228b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/IntPtrTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/IntPtrTests.cs @@ -149,7 +149,7 @@ public void ReadIntPtr_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.ReadIntPtr(null, 2)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.ReadIntPtr will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadIntPtr_NotReadable_ThrowsArgumentException() { @@ -177,7 +177,7 @@ public void WriteIntPtr_NullObject_ThrowsAccessViolationException() Assert.Throws(() => Marshal.WriteIntPtr(null, 2, (IntPtr)0)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))] [SkipOnMono("Marshal.WriteIntPtr will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteIntPtr_NotReadable_ThrowsArgumentException() { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReleaseComObjectTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReleaseComObjectTests.Windows.cs index cb63d1643598d..79f6a415ba4f7 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReleaseComObjectTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReleaseComObjectTests.Windows.cs @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices.Tests { public partial class ReleaseComObjectTests { - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void ReleaseComObject_ValidComObject_Success() { var comObject = new ComImportObject(); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReleaseComObjectTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReleaseComObjectTests.cs index ba4e30a32b662..2643098ae5a52 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReleaseComObjectTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReleaseComObjectTests.cs @@ -14,15 +14,13 @@ public void ReleaseComObject_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.FinalReleaseComObject(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void ReleaseComObject_NullObject_ThrowsNullReferenceException() { Assert.Throws(() => Marshal.ReleaseComObject(null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void ReleaseComObject_NonComObject_ThrowsArgumentException() { AssertExtensions.Throws("o", () => Marshal.ReleaseComObject(10)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.Windows.cs index a4eb867f29cd4..0f225975884f1 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.Windows.cs @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices.Tests { public partial class SetComObjectDataTests { - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void SetComObjectData_NonNullValue_Success() { var comObject = new ComImportObject(); @@ -23,7 +23,7 @@ public void SetComObjectData_NonNullValue_Success() Assert.Equal(2, Marshal.GetComObjectData(comObject, "otherKey")); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void SetComObjectData_NullValue_Success() { var comObject = new ComImportObject(); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.cs index 5d39fa5e5525f..259841bad559d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.cs @@ -14,22 +14,19 @@ public void SetComObjectData_Unix_ThrowsPlatformNotSupportedException() Assert.Throws(() => Marshal.SetComObjectData(null, null, null)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void SetComObjectData_NullObj_ThrowsArgumentNullException() { AssertExtensions.Throws("obj", () => Marshal.SetComObjectData(null, new object(), 3)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void SetComObjectData_NullKey_ThrowsArgumentNullException() { AssertExtensions.Throws("key", () => Marshal.SetComObjectData(new object(), null, 3)); } - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void SetComObjectData_NonComObjectObj_ThrowsArgumentNullException() { AssertExtensions.Throws("obj", () => Marshal.SetComObjectData(1, 2, 3)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SizeOfTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SizeOfTests.cs index a91bc349f4cec..ae7cf0f84da9a 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SizeOfTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SizeOfTests.cs @@ -78,10 +78,13 @@ public static IEnumerable SizeOf_InvalidType_TestData() yield return new object[] { typeof(GenericClass<>).GetTypeInfo().GenericTypeParameters[0], null }; - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - yield return new object[] { typeBuilder, "t" }; + if (PlatformDetection.IsReflectionEmitSupported) + { + AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run); + ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); + TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); + yield return new object[] { typeBuilder, "t" }; + } yield return new object[] { typeof(TestStructWithFxdLPSTRSAFld), null }; yield return new object[] { typeof(int[]), null }; diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ProgIdAttributeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ProgIdAttributeTests.cs index 4571920ac56f2..b61fa92d7eb8a 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ProgIdAttributeTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/ProgIdAttributeTests.cs @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices.Tests [ProgId("pizza")] public class ProgIdAttributeTests { - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void Exists() { Type type = typeof(ProgIdAttributeTests); @@ -16,7 +16,7 @@ public void Exists() Assert.Equal("pizza", attribute.Value); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] [InlineData(null)] [InlineData("ProgId")] public void Ctor_ProgId(string progId) diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/SetWin32ContextInIDispatchAttributeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/SetWin32ContextInIDispatchAttributeTests.cs deleted file mode 100644 index 10149bdc8e007..0000000000000 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/SetWin32ContextInIDispatchAttributeTests.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Reflection; -using Xunit; - -namespace System.Runtime.InteropServices.Tests -{ - public class SetWin32ContextInIDispatchAttributeTests - { - private const string TypeName = "System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute"; - - [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/50714", typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltWithAggressiveTrimming), nameof(PlatformDetection.IsBrowser))] - public void Ctor_Default_ExistsInSrc() - { - Type type = typeof(HandleCollector).Assembly.GetType(TypeName); - Assert.NotNull(type); - - ConstructorInfo constructor = type.GetConstructor(new Type[0]); - object attribute = constructor.Invoke(new object[0]); - Assert.NotNull(attribute); - } - } -}