diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 8df0c0c553d0d..54167315e8b65 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -182,9 +182,9 @@ https://github.com/dotnet/runtime 98b7ed1a3b0543a31b5a0f9069cf44cb70c9230c - + https://github.com/mono/linker - 664e78edc72dd0a48e6f55e352051b6ba61bba9a + 8d49e169d872d6225bcf73ae14ae50b002f39319 https://github.com/dotnet/xharness diff --git a/eng/Versions.props b/eng/Versions.props index ffa58723a132c..3cac4122b1fb8 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -165,7 +165,7 @@ 5.0.0-preview-20201009.2 - 6.0.100-preview.6.21362.3 + 6.0.100-preview.6.21369.3 $(MicrosoftNETILLinkTasksVersion) 6.0.0-rc.1.21366.2 diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs index 1b6c5fe1b7eb9..74feebf9a0493 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs @@ -12,6 +12,11 @@ namespace System.Data.Common { + // This coarse suppression silences all RequiresUnreferencedCode warnings in the class. + // https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "The use of GetType preserves members with RequiresUnreferencedCode, but the GetType callsites either " + + "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] public class DbConnectionStringBuilder : IDictionary, ICustomTypeDescriptor { @@ -570,7 +575,7 @@ private PropertyDescriptorCollection GetProperties(Attribute[]? attributes) } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "The type of component is statically known. This class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")] + Justification = "The component type's class name is preserved because this class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")] string? ICustomTypeDescriptor.GetClassName() { // Below call is necessary to tell the trimmer that it should mark derived types appropriately. @@ -579,7 +584,7 @@ private PropertyDescriptorCollection GetProperties(Attribute[]? attributes) return TypeDescriptor.GetClassName(this, true); } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "The type of component is statically known. This class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")] + Justification = "The component type's component name is preserved because this class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")] string? ICustomTypeDescriptor.GetComponentName() { // Below call is necessary to tell the trimmer that it should mark derived types appropriately. @@ -588,7 +593,7 @@ private PropertyDescriptorCollection GetProperties(Attribute[]? attributes) return TypeDescriptor.GetComponentName(this, true); } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "The type of component is statically known. This class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")] + Justification = "The component type's attributes are preserved because this class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")] AttributeCollection ICustomTypeDescriptor.GetAttributes() { return TypeDescriptor.GetAttributes(this, true); @@ -624,7 +629,7 @@ PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[]? at return TypeDescriptor.GetDefaultEvent(this, true); } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "The type of component is statically known. This class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")] + Justification = "The component type's events are preserved because this class is marked with [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]")] EventDescriptorCollection ICustomTypeDescriptor.GetEvents() { // Below call is necessary to tell the trimmer that it should mark derived types appropriately. diff --git a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs index 6974aafce602c..962ba8131b853 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs @@ -30,6 +30,10 @@ namespace System.Data [XmlSchemaProvider(nameof(GetDataSetSchema))] [XmlRoot(nameof(DataSet))] [System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + // This coarse suppression silences all RequiresUnreferencedCode warnings in the class. + // https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "CreateInstanceOfThisType's use of GetType uses only the parameterless constructor, but the annotations preserve all non-public constructors causing a warning for the serialization constructors. Those constructors won't be used here.")] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] // needed by Clone() to preserve derived ctors public class DataSet : MarshalByValueComponent, IListSource, IXmlSerializable, ISupportInitializeNotification, ISerializable { @@ -1093,8 +1097,6 @@ public void Clear() } } - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "Only parameterless constructors are used here but since nonPublic=true, all non-public constructors are being preserved causing a warning for the serialization constructors. Those constructors won't be used here.")] private DataSet CreateInstanceOfThisType() { return (DataSet)Activator.CreateInstance(GetType(), true)!; diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs index 22ace6fce6404..ad9044bd4a907 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs @@ -31,6 +31,10 @@ namespace System.Data [XmlSchemaProvider(nameof(GetDataTableSchema))] [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + // This coarse suppression silences all RequiresUnreferencedCode warnings in the class. + // https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] public class DataTable : MarshalByValueComponent, IListSource, ISupportInitializeNotification, ISerializable, IXmlSerializable { @@ -2307,8 +2311,6 @@ public void AcceptChanges() // Prevent inlining so that reflection calls are not moved to caller that may be in a different assembly that may have a different grant set. [MethodImpl(MethodImplOptions.NoInlining)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "Only parameterless constructors are used here. Warning is about serialization related constructors.")] protected virtual DataTable CreateInstance() => (DataTable)Activator.CreateInstance(GetType(), true)!; public virtual DataTable Clone() => Clone(null); diff --git a/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs b/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs index 5c66f68859545..64fdf03878571 100644 --- a/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs +++ b/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs @@ -12,6 +12,10 @@ namespace System.Data /// This is the generic base class for TypedDataSet /// [Serializable] + // This coarse suppression silences all RequiresUnreferencedCode warnings in the class. + // https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "DataTable.CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")] public abstract class TypedTableBase : DataTable, IEnumerable where T : DataRow { diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index d2ee34fe439d9..31daa2a57eb5f 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -160,6 +160,12 @@ namespace System.Diagnostics /// See the DiagnosticSourceEventSourceBridgeTest.cs for more explicit examples of using this bridge. /// [EventSource(Name = "Microsoft-Diagnostics-DiagnosticSource")] + // This coarse suppression silences all RequiresUnreferencedCode warnings in the class. + // https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves all members, so " + + "those that are marked with RequiresUnreferencedCode will warn. " + + "This method will not access any of these members and is safe to call.")] internal sealed class DiagnosticSourceEventSource : EventSource { public static DiagnosticSourceEventSource Log = new DiagnosticSourceEventSource(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index 4800a2cde4736..87d09e16679ed 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -233,6 +233,12 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute // The EnsureDescriptorsInitialized() method might need to access EventSource and its derived type // members and the trimmer ensures that these members are preserved. [DynamicallyAccessedMembers(ManifestMemberTypes)] + // This coarse suppression silences all RequiresUnreferencedCode warnings in the class. + // https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code. + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "EnsureDescriptorsInitialized's use of GetType preserves all members, so " + + "those that are marked with RequiresUnreferencedCode will warn. " + + "This method will not access any of these members and is safe to call.")] #endif public partial class EventSource : IDisposable { @@ -2813,16 +2819,7 @@ private void EnsureDescriptorsInitialized() { // get the metadata via reflection. Debug.Assert(m_rawManifest == null); -#if !ES_BUILD_STANDALONE - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", - Justification = "Based on the annotation on EventSource class, Trimmer will see from its analysis members " + - "that are marked with RequiresUnreferencedCode and will warn." + - "This method will not access any of these members and is safe to call.")] - byte[]? GetCreateManifestAndDescriptorsViaLocalMethod(string name) => CreateManifestAndDescriptors(this.GetType(), name, this); - m_rawManifest = GetCreateManifestAndDescriptorsViaLocalMethod(Name); -#else m_rawManifest = CreateManifestAndDescriptors(this.GetType(), Name, this); -#endif Debug.Assert(m_eventData != null); // TODO Enforce singleton pattern