From df86e2d62fa613e13b220a1dadeebc9dc2e05d25 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Sun, 2 May 2021 16:52:35 -0700 Subject: [PATCH 1/5] Fixes COm warnings --- docs/workflow/trimming/feature-switches.md | 1 + .../src/ILLink/ILLink.Substitutions.xml | 3 ++ .../ComActivationContextInternal.cs | 2 + .../Runtime/InteropServices/ComActivator.cs | 16 ++++--- .../InteropServices/Marshal.CoreCLR.cs | 45 +++++++++++-------- .../src/System/RuntimeType.CoreCLR.cs | 2 +- src/coreclr/vm/ecalllist.h | 2 +- src/coreclr/vm/eeconfig.cpp | 2 +- src/coreclr/vm/marshalnative.cpp | 4 +- src/coreclr/vm/marshalnative.h | 2 +- .../src/ILLink/ILLink.Suppressions.Shared.xml | 42 ----------------- ...e.InteropServices.ComDisabled.Tests.csproj | 2 +- .../Marshal/MarshalComDisabledTests.cs | 4 +- 13 files changed, 52 insertions(+), 75 deletions(-) diff --git a/docs/workflow/trimming/feature-switches.md b/docs/workflow/trimming/feature-switches.md index 1171f8fb4b6d2..15507d597b42a 100644 --- a/docs/workflow/trimming/feature-switches.md +++ b/docs/workflow/trimming/feature-switches.md @@ -20,6 +20,7 @@ configurations but their defaults might vary as any SDK can set the defaults dif | TBD | System.Threading.ThreadPool.EnableDispatchAutoreleasePool | When set to true, creates an NSAutoreleasePool around each thread pool work item on applicable platforms. | | CustomResourceTypesSupport | System.Resources.ResourceManager.AllowCustomResourceTypes | Use of custom resource types is disabled when set to false. ResourceManager code paths that use reflection for custom types can be trimmed. | | EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | BinaryFormatter serialization support is trimmed when set to false. | +| BuiltInComSupport | System.Runtime.InteropServices.Marshal.IsBuiltInComSupported | In-built COM support is trimmed when set to false. | Any feature-switch which defines property can be set in csproj file or on the command line as any other MSBuild property. Those without predefined property name diff --git a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml index 7953cca3a6c10..5516021ec3659 100644 --- a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml +++ b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml @@ -3,5 +3,8 @@ + + + \ No newline at end of file diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs index 015843165977f..1db025ed86581 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivationContextInternal.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace Internal.Runtime.InteropServices @@ -39,6 +40,7 @@ public partial struct ComActivationContext [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IClassFactory { + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] void CreateInstance( [MarshalAs(UnmanagedType.Interface)] object? pUnkOuter, ref Guid riid, diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index d28441194f4a3..37a324445468c 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -35,6 +35,7 @@ internal struct LICINFO [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] internal interface IClassFactory2 : IClassFactory { + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] new void CreateInstance( [MarshalAs(UnmanagedType.Interface)] object? pUnkOuter, ref Guid riid, @@ -62,7 +63,7 @@ public partial struct ComActivationContext [CLSCompliant(false)] public static unsafe ComActivationContext Create(ref ComActivationContextInternal cxtInt) { - if (!Marshal.IsComSupported) + if (!Marshal.IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -92,7 +93,7 @@ public static class ComActivator [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public static object GetClassFactoryForType(ComActivationContext cxt) { - if (!Marshal.IsComSupported) + if (!Marshal.IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -126,7 +127,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt) [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bool register) { - if (!Marshal.IsComSupported) + if (!Marshal.IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -222,7 +223,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo [UnmanagedCallersOnly] public static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInternal* pCxtInt) { - if (!Marshal.IsComSupported) + if (!Marshal.IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -265,7 +266,7 @@ public static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInte [UnmanagedCallersOnly] public static unsafe int RegisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) { - if (!Marshal.IsComSupported) + if (!Marshal.IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -311,7 +312,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern [UnmanagedCallersOnly] public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInternal* pCxtInt) { - if (!Marshal.IsComSupported) + if (!Marshal.IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -364,6 +365,7 @@ private static void Log(string fmt, params object[] args) Debug.WriteLine(fmt, args); } + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] private static Type FindClassType(Guid clsid, string assemblyPath, string assemblyName, string typeName) { try @@ -489,6 +491,7 @@ public static object CreateAggregatedObject(object pUnkOuter, object comObject) } } + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public void CreateInstance( [MarshalAs(UnmanagedType.Interface)] object? pUnkOuter, ref Guid riid, @@ -524,6 +527,7 @@ public LicenseClassFactory(Guid clsid, Type classType) _classType = classType; } + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] public void CreateInstance( [MarshalAs(UnmanagedType.Interface)] object? pUnkOuter, ref Guid riid, diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs index 46ea1bb35438c..3e0cad94ed05d 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs @@ -196,7 +196,7 @@ private static void PrelinkCore(MethodInfo m) private static extern void InternalPrelink(RuntimeMethodHandleInternal m); [DllImport(RuntimeHelpers.QCall)] - private static extern bool IsComSupportedInternal(); + private static extern bool IsBuiltInComSupportedInternal(); [MethodImpl(MethodImplOptions.InternalCall)] public static extern /* struct _EXCEPTION_POINTERS* */ IntPtr GetExceptionPointers(); @@ -236,9 +236,9 @@ private static object PtrToStructureHelper(IntPtr ptr, Type structureType) [MethodImpl(MethodImplOptions.InternalCall)] internal static extern bool IsPinnable(object? obj); - internal static bool IsComSupported { get; } = InitializeIsComSupported(); + internal static bool IsBuiltInComSupported { get; } = InitializeIsBuiltInComSupported(); - private static bool InitializeIsComSupported() => IsComSupportedInternal(); + private static bool InitializeIsBuiltInComSupported() => IsBuiltInComSupportedInternal(); #if TARGET_WINDOWS /// @@ -296,7 +296,7 @@ public static string GetTypeInfoName(ITypeInfo typeInfo) // on Marshal for more consistent API surface. internal static Type? GetTypeFromCLSID(Guid clsid, string? server, bool throwOnError) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -443,7 +443,7 @@ public static object GetUniqueObjectForIUnknown(IntPtr unknown) [SupportedOSPlatform("windows")] public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -457,7 +457,7 @@ public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o) [SupportedOSPlatform("windows")] public static IntPtr CreateAggregatedObject(IntPtr pOuter, T o) where T : notnull { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -484,7 +484,7 @@ public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o) [SupportedOSPlatform("windows")] public static int ReleaseComObject(object o) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -512,7 +512,7 @@ public static int ReleaseComObject(object o) [SupportedOSPlatform("windows")] public static int FinalReleaseComObject(object o) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -536,7 +536,7 @@ public static int FinalReleaseComObject(object o) [SupportedOSPlatform("windows")] public static object? GetComObjectData(object obj, object key) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -567,7 +567,7 @@ public static int FinalReleaseComObject(object o) [SupportedOSPlatform("windows")] public static bool SetComObjectData(object obj, object key, object? data) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -597,7 +597,7 @@ public static bool SetComObjectData(object obj, object key, object? data) [return: NotNullIfNotNull("o")] public static object? CreateWrapperOfType(object? o, Type t) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -652,7 +652,7 @@ public static bool SetComObjectData(object obj, object key, object? data) [SupportedOSPlatform("windows")] public static TWrapper CreateWrapperOfType(T? o) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -672,7 +672,7 @@ public static bool SetComObjectData(object obj, object key, object? data) [SupportedOSPlatform("windows")] public static void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr pDstNativeVariant) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -686,7 +686,7 @@ public static void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr [SupportedOSPlatform("windows")] public static void GetNativeVariantForObject(T? obj, IntPtr pDstNativeVariant) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -697,7 +697,7 @@ public static void GetNativeVariantForObject(T? obj, IntPtr pDstNativeVariant [SupportedOSPlatform("windows")] public static object? GetObjectForNativeVariant(/* VARIANT * */ IntPtr pSrcNativeVariant) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -711,7 +711,7 @@ public static void GetNativeVariantForObject(T? obj, IntPtr pDstNativeVariant [SupportedOSPlatform("windows")] public static T? GetObjectForNativeVariant(IntPtr pSrcNativeVariant) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -722,7 +722,7 @@ public static void GetNativeVariantForObject(T? obj, IntPtr pDstNativeVariant [SupportedOSPlatform("windows")] public static object?[] GetObjectsForNativeVariants(/* VARIANT * */ IntPtr aSrcNativeVariant, int cVars) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -736,7 +736,7 @@ public static void GetNativeVariantForObject(T? obj, IntPtr pDstNativeVariant [SupportedOSPlatform("windows")] public static T[] GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -764,10 +764,11 @@ public static T[] GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int c [MethodImpl(MethodImplOptions.InternalCall)] public static extern int GetEndComSlot(Type t); + [RequiresUnreferencedCode("Built-in COM support is not trim compatible", Url = "https://aka.ms/dotnet-illink/com")] [SupportedOSPlatform("windows")] public static object BindToMoniker(string monikerName) { - if (!IsComSupported) + if (!IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } @@ -780,12 +781,18 @@ public static object BindToMoniker(string monikerName) return obj; } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", + Justification = "The calling method is guarded")] [DllImport(Interop.Libraries.Ole32, PreserveSig = false)] private static extern void CreateBindCtx(uint reserved, out IBindCtx ppbc); + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", + Justification = "The calling method is guarded")] [DllImport(Interop.Libraries.Ole32, PreserveSig = false)] private static extern void MkParseDisplayName(IBindCtx pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IMoniker ppmk); + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", + Justification = "The calling method is guarded")] [DllImport(Interop.Libraries.Ole32, PreserveSig = false)] private static extern void BindMoniker(IMoniker pmk, uint grfOpt, ref Guid iidResult, [MarshalAs(UnmanagedType.Interface)] out object ppvResult); diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs index f645ad15a4073..d01d077b47368 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs @@ -3680,7 +3680,7 @@ internal static object CreateEnum(RuntimeType enumType, long value) Type[] aArgsTypes, Type retType) { - if (!Marshal.IsComSupported) + if (!Marshal.IsBuiltInComSupported) { throw new NotSupportedException(SR.NotSupported_COM); } diff --git a/src/coreclr/vm/ecalllist.h b/src/coreclr/vm/ecalllist.h index d309500d50f94..eacef79a9b9ab 100644 --- a/src/coreclr/vm/ecalllist.h +++ b/src/coreclr/vm/ecalllist.h @@ -758,7 +758,7 @@ FCFuncStart(gInteropMarshalFuncs) FCFuncElement("OffsetOfHelper", MarshalNative::OffsetOfHelper) QCFuncElement("InternalPrelink", MarshalNative::Prelink) - QCFuncElement("IsComSupportedInternal", MarshalNative::IsComSupported) + QCFuncElement("IsBuiltInComSupportedInternal", MarshalNative::IsBuiltInComSupported) FCFuncElement("GetExceptionForHRInternal", MarshalNative::GetExceptionForHR) FCFuncElement("GetDelegateForFunctionPointerInternal", MarshalNative::GetDelegateForFunctionPointerInternal) FCFuncElement("GetFunctionPointerForDelegateInternal", MarshalNative::GetFunctionPointerForDelegateInternal) diff --git a/src/coreclr/vm/eeconfig.cpp b/src/coreclr/vm/eeconfig.cpp index 778edeadae63c..dafcb7eb419d2 100644 --- a/src/coreclr/vm/eeconfig.cpp +++ b/src/coreclr/vm/eeconfig.cpp @@ -683,7 +683,7 @@ HRESULT EEConfig::sync() bLogCCWRefCountChange = true; fEnableRCWCleanupOnSTAShutdown = (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EnableRCWCleanupOnSTAShutdown) != 0); - m_fBuiltInCOMInteropSupported = Configuration::GetKnobBooleanValue(W("System.Runtime.InteropServices.Marshal.IsComSupported"), true); + m_fBuiltInCOMInteropSupported = Configuration::GetKnobBooleanValue(W("System.Runtime.InteropServices.Marshal.IsBuiltInComSupported"), true); #endif // FEATURE_COMINTEROP #ifdef _DEBUG diff --git a/src/coreclr/vm/marshalnative.cpp b/src/coreclr/vm/marshalnative.cpp index 86046fccdcec4..01702b772e127 100644 --- a/src/coreclr/vm/marshalnative.cpp +++ b/src/coreclr/vm/marshalnative.cpp @@ -69,10 +69,10 @@ VOID QCALLTYPE MarshalNative::Prelink(MethodDesc * pMD) END_QCALL; } -// IsComSupported +// IsBuiltInComSupported // Built-in COM support is only checked from the native side to ensure the runtime // is in a consistent state -BOOL QCALLTYPE MarshalNative::IsComSupported() +BOOL QCALLTYPE MarshalNative::IsBuiltInComSupported() { QCALL_CONTRACT; diff --git a/src/coreclr/vm/marshalnative.h b/src/coreclr/vm/marshalnative.h index 5971225d22d59..3036d38f5e5e6 100644 --- a/src/coreclr/vm/marshalnative.h +++ b/src/coreclr/vm/marshalnative.h @@ -20,7 +20,7 @@ class MarshalNative { public: static VOID QCALLTYPE Prelink(MethodDesc * pMD); - static BOOL QCALLTYPE IsComSupported(); + static BOOL QCALLTYPE IsBuiltInComSupported(); //==================================================================== // These methods convert between an HR and and a managed exception. diff --git a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.Shared.xml b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.Shared.xml index 5b8326f6ff097..2b5f6ef8918c0 100644 --- a/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.Shared.xml +++ b/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.Shared.xml @@ -1,12 +1,6 @@  - - ILLink - IL2026 - member - M:Internal.Runtime.InteropServices.ComActivator.FindClassType(System.Guid,System.String,System.String,System.String) - ILLink IL2072 @@ -19,53 +13,17 @@ member M:Internal.Runtime.InteropServices.IsolatedComponentLoadContext.Load(System.Reflection.AssemblyName) - - ILLink - IL2050 - member - M:System.Runtime.InteropServices.Marshal.BindMoniker(System.Runtime.InteropServices.ComTypes.IMoniker,System.UInt32,System.Guid@,System.Object@) - - - ILLink - IL2050 - member - M:System.Runtime.InteropServices.Marshal.CreateBindCtx(System.UInt32,System.Runtime.InteropServices.ComTypes.IBindCtx@) - - - ILLink - IL2050 - member - M:System.Runtime.InteropServices.Marshal.MkParseDisplayName(System.Runtime.InteropServices.ComTypes.IBindCtx,System.String,System.UInt32@,System.Runtime.InteropServices.ComTypes.IMoniker@) - - - ILLink - IL2057 - member - M:Internal.Runtime.InteropServices.ComActivator.ClassRegistrationScenarioForType(Internal.Runtime.InteropServices.ComActivationContext,System.Boolean) - ILLink IL2057 member M:Internal.Runtime.InteropServices.ComponentActivator.InternalGetFunctionPointer(System.Runtime.Loader.AssemblyLoadContext,System.String,System.String,System.IntPtr) - - ILLink - IL2075 - member - M:Internal.Runtime.InteropServices.ComActivator.ClassRegistrationScenarioForType(Internal.Runtime.InteropServices.ComActivationContext,System.Boolean) - ILLink IL2075 member M:Internal.Runtime.InteropServices.ComponentActivator.InternalGetFunctionPointer(System.Runtime.Loader.AssemblyLoadContext,System.String,System.String,System.IntPtr) - - ILLink - IL2077 - member - M:Internal.Runtime.InteropServices.ComActivator.BasicClassFactory.CreateInstance(System.Object,System.Guid@,System.IntPtr@) - diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System.Runtime.InteropServices.ComDisabled.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System.Runtime.InteropServices.ComDisabled.Tests.csproj index f06c7c65cd2e2..4bc8dec6844ef 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System.Runtime.InteropServices.ComDisabled.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System.Runtime.InteropServices.ComDisabled.Tests.csproj @@ -10,6 +10,6 @@ - + diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs b/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs index 4a927df56cdf6..8511a4c567071 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs @@ -1,4 +1,6 @@ -//using System.Runtime.InteropServices.Tests.Common; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + using Xunit; namespace System.Runtime.InteropServices.Tests From f3d95f3494a2e6a47ce1d5c1d99a4c3a7f79078e Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 3 May 2021 04:37:47 -0700 Subject: [PATCH 2/5] fb --- .../src/System/Runtime/InteropServices/Marshal.CoreCLR.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs index 3e0cad94ed05d..ca3218626370c 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs @@ -782,17 +782,17 @@ public static object BindToMoniker(string monikerName) } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", - Justification = "The calling method is guarded")] + Justification = "The calling method is annotated with RequiresUnreferencedCode")] [DllImport(Interop.Libraries.Ole32, PreserveSig = false)] private static extern void CreateBindCtx(uint reserved, out IBindCtx ppbc); [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", - Justification = "The calling method is guarded")] + Justification = "The calling method is annotated with RequiresUnreferencedCode")] [DllImport(Interop.Libraries.Ole32, PreserveSig = false)] private static extern void MkParseDisplayName(IBindCtx pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IMoniker ppmk); [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", - Justification = "The calling method is guarded")] + Justification = "The calling method is annotated with RequiresUnreferencedCode")] [DllImport(Interop.Libraries.Ole32, PreserveSig = false)] private static extern void BindMoniker(IMoniker pmk, uint grfOpt, ref Guid iidResult, [MarshalAs(UnmanagedType.Interface)] out object ppvResult); From 61b08f4b269b3f15762cb995bc54e4ea622c72d9 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 4 May 2021 12:53:02 -0700 Subject: [PATCH 3/5] feedback --- docs/workflow/trimming/feature-switches.md | 2 +- .../src/System/Runtime/InteropServices/Marshal.CoreCLR.cs | 5 ++--- src/coreclr/vm/eeconfig.cpp | 2 +- .../System.Runtime.InteropServices.ComDisabled.Tests.csproj | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/workflow/trimming/feature-switches.md b/docs/workflow/trimming/feature-switches.md index 15507d597b42a..e0f54a14a044b 100644 --- a/docs/workflow/trimming/feature-switches.md +++ b/docs/workflow/trimming/feature-switches.md @@ -20,7 +20,7 @@ configurations but their defaults might vary as any SDK can set the defaults dif | TBD | System.Threading.ThreadPool.EnableDispatchAutoreleasePool | When set to true, creates an NSAutoreleasePool around each thread pool work item on applicable platforms. | | CustomResourceTypesSupport | System.Resources.ResourceManager.AllowCustomResourceTypes | Use of custom resource types is disabled when set to false. ResourceManager code paths that use reflection for custom types can be trimmed. | | EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | BinaryFormatter serialization support is trimmed when set to false. | -| BuiltInComSupport | System.Runtime.InteropServices.Marshal.IsBuiltInComSupported | In-built COM support is trimmed when set to false. | +| BuiltInComInteropSupport | System.Runtime.InteropServices.BuiltInComInterop.IsSupported | In-built COM support is trimmed when set to false. | Any feature-switch which defines property can be set in csproj file or on the command line as any other MSBuild property. Those without predefined property name diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs index ca3218626370c..ddc25611df49a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs @@ -236,9 +236,7 @@ private static object PtrToStructureHelper(IntPtr ptr, Type structureType) [MethodImpl(MethodImplOptions.InternalCall)] internal static extern bool IsPinnable(object? obj); - internal static bool IsBuiltInComSupported { get; } = InitializeIsBuiltInComSupported(); - - private static bool InitializeIsBuiltInComSupported() => IsBuiltInComSupportedInternal(); + internal static bool IsBuiltInComSupported { get; } = IsBuiltInComSupportedInternal(); #if TARGET_WINDOWS /// @@ -781,6 +779,7 @@ public static object BindToMoniker(string monikerName) return obj; } + // Revist after https://github.com/mono/linker/issues/1989 is fixed [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern", Justification = "The calling method is annotated with RequiresUnreferencedCode")] [DllImport(Interop.Libraries.Ole32, PreserveSig = false)] diff --git a/src/coreclr/vm/eeconfig.cpp b/src/coreclr/vm/eeconfig.cpp index dafcb7eb419d2..b3bf5bde94bd1 100644 --- a/src/coreclr/vm/eeconfig.cpp +++ b/src/coreclr/vm/eeconfig.cpp @@ -683,7 +683,7 @@ HRESULT EEConfig::sync() bLogCCWRefCountChange = true; fEnableRCWCleanupOnSTAShutdown = (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EnableRCWCleanupOnSTAShutdown) != 0); - m_fBuiltInCOMInteropSupported = Configuration::GetKnobBooleanValue(W("System.Runtime.InteropServices.Marshal.IsBuiltInComSupported"), true); + m_fBuiltInCOMInteropSupported = Configuration::GetKnobBooleanValue(W("System.Runtime.InteropServices.BuiltInComInterop.IsSupported"), true); #endif // FEATURE_COMINTEROP #ifdef _DEBUG diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System.Runtime.InteropServices.ComDisabled.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System.Runtime.InteropServices.ComDisabled.Tests.csproj index 4bc8dec6844ef..e0e9e306d0700 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System.Runtime.InteropServices.ComDisabled.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/ComDisabled/System.Runtime.InteropServices.ComDisabled.Tests.csproj @@ -10,6 +10,6 @@ - + From 093fa5fdd75d900539ebe17026d571b0762443e7 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 6 May 2021 07:57:16 -0700 Subject: [PATCH 4/5] missed one name change --- .../src/ILLink/ILLink.Substitutions.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml index 5516021ec3659..ef9f087a33e80 100644 --- a/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml +++ b/src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml @@ -3,8 +3,8 @@ - + - \ No newline at end of file + From e9626049d7c78a7b0daa8f8b66dca14534cdb1fd Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 7 May 2021 03:45:35 -0700 Subject: [PATCH 5/5] Update docs/workflow/trimming/feature-switches.md Co-authored-by: Elinor Fung --- docs/workflow/trimming/feature-switches.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/workflow/trimming/feature-switches.md b/docs/workflow/trimming/feature-switches.md index e0f54a14a044b..84f4aad6faba8 100644 --- a/docs/workflow/trimming/feature-switches.md +++ b/docs/workflow/trimming/feature-switches.md @@ -20,7 +20,7 @@ configurations but their defaults might vary as any SDK can set the defaults dif | TBD | System.Threading.ThreadPool.EnableDispatchAutoreleasePool | When set to true, creates an NSAutoreleasePool around each thread pool work item on applicable platforms. | | CustomResourceTypesSupport | System.Resources.ResourceManager.AllowCustomResourceTypes | Use of custom resource types is disabled when set to false. ResourceManager code paths that use reflection for custom types can be trimmed. | | EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization | BinaryFormatter serialization support is trimmed when set to false. | -| BuiltInComInteropSupport | System.Runtime.InteropServices.BuiltInComInterop.IsSupported | In-built COM support is trimmed when set to false. | +| BuiltInComInteropSupport | System.Runtime.InteropServices.BuiltInComInterop.IsSupported | Built-in COM support is trimmed when set to false. | Any feature-switch which defines property can be set in csproj file or on the command line as any other MSBuild property. Those without predefined property name