diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index 06065b062a6444..e23fafac09bb03 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -186,9 +186,9 @@
https://github.com/dotnet/runtime
f7e4c261815c66fde2c1e750b744f193e236c17e
-
+
https://github.com/mono/linker
- 0cb9250a903cfc90cbac602ed79c0cbc588d8d3f
+ ae18468b8712503aee67911228dd921601bd423a
https://github.com/dotnet/xharness
diff --git a/eng/Versions.props b/eng/Versions.props
index 55b4a8cd92b07e..84011548e924c9 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -166,7 +166,7 @@
5.0.0-preview-20201009.2
- 6.0.100-preview.6.21378.1
+ 6.0.100-preview.6.21402.2
$(MicrosoftNETILLinkTasksVersion)
6.0.0-rc.1.21369.1
diff --git a/eng/testing/linker/SupportFiles/Directory.Build.props b/eng/testing/linker/SupportFiles/Directory.Build.props
index 760ff6d86e8102..458994a1822ebd 100644
--- a/eng/testing/linker/SupportFiles/Directory.Build.props
+++ b/eng/testing/linker/SupportFiles/Directory.Build.props
@@ -17,6 +17,8 @@
false
true
+
+ $(NoWarn);IL2111
diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets
index 6c01e8c8967420..3beee87d760495 100644
--- a/eng/testing/tests.mobile.targets
+++ b/eng/testing/tests.mobile.targets
@@ -17,6 +17,8 @@
true
true
+
+ $(NoWarn);IL2111
false
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 b8e21637d48510..6fdf4b2e5c3116 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
@@ -523,10 +523,10 @@ private sealed class LicenseClassFactory : IClassFactory2
private readonly LicenseInteropProxy _licenseProxy = new LicenseInteropProxy();
private readonly Guid _classId;
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicConstructors)]
private readonly Type _classType;
- public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type classType)
+ public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicConstructors)] Type classType)
{
_classId = clsid;
_classType = classType;
@@ -627,6 +627,9 @@ internal sealed class LicenseInteropProxy
private object? _licContext;
private Type? _targetRcwType;
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
+ Justification = "The type parameter to LicenseManager.CreateWithContext method has PublicConstructors annotation. We only invoke this method" +
+ "from AllocateAndValidateLicense which annotates the value passed in with the same annotation.")]
public LicenseInteropProxy()
{
Type licManager = Type.GetType("System.ComponentModel.LicenseManager, System.ComponentModel.TypeConverter", throwOnError: true)!;
@@ -742,7 +745,7 @@ public string RequestLicKey(Type type)
// If we are being entered because of a call to ICF::CreateInstanceLic(),
// "isDesignTime" will be "false" and "key" will point to a non-null
// license key.
- public object AllocateAndValidateLicense(Type type, string? key, bool isDesignTime)
+ public object AllocateAndValidateLicense([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, string? key, bool isDesignTime)
{
object?[] parameters;
object? licContext;
diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb
index 9644a77fd43df3..cd20c961272056 100644
--- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb
+++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb
@@ -824,6 +824,8 @@ Namespace Microsoft.VisualBasic.CompilerServices
+
Public Overrides Function FallbackConvert(
ByVal target As DynamicMetaObject,
ByVal errorSuggestion As DynamicMetaObject) As DynamicMetaObject
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 74feebf9a04936..13552bc01785ef 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,10 +12,8 @@
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 "
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode",
+ Justification = "The use of GetType preserves ICustomTypeDescriptor 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
@@ -393,6 +391,9 @@ internal Attribute[] GetAttributesFromCollection(AttributeCollection collection)
return attributes;
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
+ + "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
private PropertyDescriptorCollection GetProperties()
{
@@ -419,6 +420,9 @@ private PropertyDescriptorCollection GetProperties()
return propertyDescriptors;
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
+ + "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
protected virtual void GetProperties(Hashtable propertyDescriptors)
{
@@ -526,6 +530,9 @@ protected virtual void GetProperties(Hashtable propertyDescriptors)
}
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
+ + "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
private PropertyDescriptorCollection GetProperties(Attribute[]? attributes)
{
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 962ba8131b8531..b2a85e44b382eb 100644
--- a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs
+++ b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs
@@ -30,10 +30,6 @@ 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
{
@@ -231,11 +227,15 @@ protected void GetSerializationData(SerializationInfo info, StreamingContext con
// Deserialize all the tables schema and data of the dataset from binary/xml stream.
[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)]
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ 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.")]
protected DataSet(SerializationInfo info, StreamingContext context) : this(info, context, true)
{
}
[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)]
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ 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.")]
protected DataSet(SerializationInfo info, StreamingContext context, bool ConstructSchema) : this()
{
SerializationFormat remotingFormat = SerializationFormat.Xml;
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 ad9044bd4a9076..08648e6d29c26c 100644
--- a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs
+++ b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs
@@ -31,10 +31,6 @@ 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
{
@@ -196,6 +192,8 @@ public DataTable(string? tableName, string? tableNamespace) : this(tableName)
}
// Deserialize the table from binary/xml stream.
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
protected DataTable(SerializationInfo info, StreamingContext context) : this()
{
diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs
index 2a14fa8f444764..58d56a332c63a1 100644
--- a/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs
+++ b/src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs
@@ -737,7 +737,14 @@ internal static DataTable GetSchemaTableFromDataTable(DataTable table)
DataColumn ColumnSize = new DataColumn(SchemaTableColumn.ColumnSize, typeof(int));
DataColumn NumericPrecision = new DataColumn(SchemaTableColumn.NumericPrecision, typeof(short));
DataColumn NumericScale = new DataColumn(SchemaTableColumn.NumericScale, typeof(short));
- DataColumn DataType = new DataColumn(SchemaTableColumn.DataType, typeof(Type));
+ DataColumn DataType = GetSystemTypeDataColumn();
+
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
+ Justification = "The problem is Type.TypeInitializer which requires constructors on the Type instance." +
+ "In this case the TypeInitializer property is not accessed dynamically.")]
+ static DataColumn GetSystemTypeDataColumn() =>
+ new DataColumn(SchemaTableColumn.DataType, typeof(Type));
+
DataColumn ProviderType = new DataColumn(SchemaTableColumn.ProviderType, typeof(int));
DataColumn IsLong = new DataColumn(SchemaTableColumn.IsLong, typeof(bool));
DataColumn AllowDBNull = new DataColumn(SchemaTableColumn.AllowDBNull, typeof(bool));
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 64fdf03878571a..de17c7d2d82e44 100644
--- a/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs
+++ b/src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs
@@ -12,10 +12,6 @@ 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
{
@@ -32,6 +28,8 @@ protected TypedTableBase() : base() { }
///
/// SerializationInfo containing data to construct the object.
/// The streaming context for the object being deserialized.
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "DataTable.CreateInstance's use of GetType uses only the parameterless constructor, not this serialization related constructor.")]
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
protected TypedTableBase(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
diff --git a/src/libraries/System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml b/src/libraries/System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml
index 63d7bd6ef89fd9..d54caa4452859d 100644
--- a/src/libraries/System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml
+++ b/src/libraries/System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml
@@ -97,5 +97,10 @@
member
M:System.Data.OleDb.OleDbDataReader.GetFieldType(System.Int32)
-
+
+ ILLink
+ IL2111
+ member
+ M:System.Data.OleDb.OleDbDataReader.BuildSchemaTable(MetaData[])
+
\ No newline at end of file
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 31daa2a57eb5f9..c7b92ad12ff2de 100644
--- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
+++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
@@ -160,12 +160,17 @@ 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.")]
+ // These suppressions can go away with https://github.com/mono/linker/issues/2175
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode",
+ Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " +
+ "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " +
+ "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " +
+ "EnsureDescriptorsInitialized does not access these members and is safe to call.")]
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:ReflectionToDynamicallyAccessedMembers",
+ Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " +
+ "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " +
+ "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " +
+ "EnsureDescriptorsInitialized does not access these members and is safe to call.")]
internal sealed class DiagnosticSourceEventSource : EventSource
{
public static DiagnosticSourceEventSource Log = new DiagnosticSourceEventSource();
@@ -1019,6 +1024,9 @@ private void Dispose()
}
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)]
public List> Morph(object? args)
{
@@ -1100,6 +1108,9 @@ private void Dispose()
// Given a type generate all the implicit transforms for type (that is for every field
// generate the spec that fetches it).
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)]
private static TransformSpec? MakeImplicitTransforms(Type type)
{
@@ -1195,6 +1206,9 @@ public TransformSpec(string transformSpec, int startIdx, int endIdx, TransformSp
/// if the spec is OUTSTR=EVENT_VALUE.PROP1.PROP2.PROP3 and the ultimate value of PROP3 is
/// 10 then the return key value pair is KeyValuePair("OUTSTR","10")
///
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)]
public KeyValuePair Morph(object? obj)
{
@@ -1246,6 +1260,9 @@ public PropertySpec(string propertyName, PropertySpec? next)
/// Given an object fetch the property that this PropertySpec represents.
/// obj may be null when IsStatic is true, otherwise it must be non-null.
///
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)]
public object? Fetch(object? obj)
{
@@ -1289,6 +1306,9 @@ public PropertyFetch(Type? type)
///
/// Create a property fetcher for a propertyName
///
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "In EventSource, EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(DiagnosticSource.WriteRequiresUnreferencedCode)]
public static PropertyFetch FetcherForProperty(Type? type, string propertyName)
{
diff --git a/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs b/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs
index 91929da00c0463..92dfa41915d144 100644
--- a/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs
+++ b/src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Tracing;
using System.Linq;
using System;
diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs
index bd6cfe7144b59b..4f0ed87b7132b2 100644
--- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs
+++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs
@@ -60,6 +60,9 @@ private TypeBuilder DefineType(string name, [DynamicallyAccessedMembers(Dynamica
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "MulticastDelegate has a ctor with RequiresUnreferencedCode, but the generated derived type doesn't reference this ctor, so this is trim compatible.")]
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
+ Justification = "MulticastDelegate and Delegate have multiple methods with DynamicallyAccessedMembers annotations. But the generated code" +
+ "in this case will not call any of them (it only defines a .ctor and Invoke method both of which are runtime implemented.")]
internal static TypeBuilder DefineDelegateType(string name)
{
return Assembly.DefineType(
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 e47a6127022cf9..789a510bece129 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,12 +233,16 @@ 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.")]
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " +
+ "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " +
+ "This includes Delegate and MulticastDelegate methods which require unreferenced code, but " +
+ "EnsureDescriptorsInitialized does not access these members and is safe to call.")]
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2115:ReflectionToDynamicallyAccessedMembers",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves methods on Delegate and MulticastDelegate " +
+ "because the nested type OverrideEventProvider's base type EventProvider defines a delegate. " +
+ "This includes Delegate and MulticastDelegate methods which have dynamically accessed members requirements, but " +
+ "EnsureDescriptorsInitialized does not access these members and is safe to call.")]
#endif
public partial class EventSource : IDisposable
{
@@ -367,6 +371,12 @@ public static string GetName(Type eventSourceType)
/// The manifest XML fragment contains the string name of the DLL name in
/// which it is embedded. This parameter specifies what name will be used
/// The XML data string
+#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+
+ "access this member and is safe to call.")]
+#endif
public static string? GenerateManifest(
#if !ES_BUILD_STANDALONE
[DynamicallyAccessedMembers(ManifestMemberTypes)]
@@ -388,6 +398,12 @@ public static string GetName(Type eventSourceType)
/// The flags to customize manifest generation. If flags has bit OnlyIfNeededForRegistration specified
/// this returns null when the eventSourceType does not require explicit registration
/// The XML data string or null
+#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+
+ "access this member and is safe to call.")]
+#endif
public static string? GenerateManifest(
#if !ES_BUILD_STANDALONE
[DynamicallyAccessedMembers(ManifestMemberTypes)]
@@ -1269,6 +1285,9 @@ internal unsafe void SetMetadata(byte* pointer, int size, int reserved)
///
///
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
#endif
[CLSCompliant(false)]
@@ -1303,6 +1322,9 @@ protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSourc
///
///
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
#endif
[CLSCompliant(false)]
@@ -1398,6 +1420,9 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel
/// check so that the varargs call is not made when the EventSource is not active.
///
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
#endif
protected unsafe void WriteEvent(int eventId, params object?[] args)
@@ -1414,6 +1439,9 @@ protected unsafe void WriteEvent(int eventId, params object?[] args)
/// check so that the varargs call is not made when the EventSource is not active.
///
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
#endif
protected unsafe void WriteEventWithRelatedActivityId(int eventId, Guid relatedActivityId, params object?[] args)
@@ -1898,6 +1926,9 @@ private static unsafe void AssertValidString(EventData* data)
}
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
#endif
private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object?[] args)
@@ -2010,6 +2041,9 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object
}
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
#endif
private unsafe object?[] SerializeEventArgs(int eventId, object?[] args)
@@ -2469,6 +2503,9 @@ internal partial struct EventMetadata
public TraceLoggingEventTypes TraceLoggingEventTypes
{
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
#endif
get
@@ -2956,6 +2993,12 @@ internal static bool IsCustomAttributeDefinedHelper(
// Helper to deal with the fact that the type we are reflecting over might be loaded in the ReflectionOnly context.
// When that is the case, we have the build the custom assemblies on a member by hand.
+#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not "+
+ "access this member and is safe to call.")]
+#endif
internal static Attribute? GetCustomAttributeHelper(
MemberInfo member,
#if !ES_BUILD_STANDALONE
@@ -3077,6 +3120,12 @@ private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAt
// return the UTF8 bytes. It also sets up the code:EventData structures needed to dispatch events
// at run time. 'source' is the event source to place the descriptors. If it is null,
// then the descriptors are not created, and just the manifest is generated.
+#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "has dynamically accessed members requirements, but its use of this method satisfies " +
+ "these requirements because it passes in the result of GetType with the same annotations.")]
+#endif
private static byte[]? CreateManifestAndDescriptors(
#if !ES_BUILD_STANDALONE
[DynamicallyAccessedMembers(ManifestMemberTypes)]
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
index c51d731e0c61e8..b6b739f3eeeb50 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
@@ -163,6 +163,9 @@ public unsafe void Write(string? eventName, EventSourceOptions options)
/// create the fields of the event.
///
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(
#else
@@ -204,6 +207,9 @@ public unsafe void Write(
/// create the fields of the event.
///
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(
#else
@@ -247,6 +253,9 @@ public unsafe void Write(
/// create the fields of the event.
///
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(
#else
@@ -297,6 +306,9 @@ public unsafe void Write(
/// create the fields of the event.
///
#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
+ Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
+ "requires unreferenced code, but EnsureDescriptorsInitialized does not access this member and is safe to call.")]
[RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)]
public unsafe void Write<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(
#else
diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs
index 8793954253a002..f7513edfd6720b 100644
--- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs
+++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs
@@ -345,7 +345,12 @@ internal sealed class NullPrimitiveDataContract : PrimitiveDataContract
{
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "This warns because the call to Base has the type annotated with DynamicallyAccessedMembers so it warns" +
- "when looking into the methods of NullPrimitiveDataContract. Because this just represents null, we suppress.")]
+ "when looking into the methods of NullPrimitiveDataContract which are annotated with RequiresUnreferencedCodeAttribute. " +
+ "Because this just represents null, we suppress.")]
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
+ Justification = "This warns because the call to Base has the type annotated with DynamicallyAccessedMembers so it warns" +
+ "when looking into the methods of NullPrimitiveDataContract which are annotated with DynamicallyAccessedMembersAttribute. " +
+ "Because this just represents null, we suppress.")]
public NullPrimitiveDataContract() : base(typeof(NullPrimitiveDataContract), DictionaryGlobals.EmptyString, DictionaryGlobals.EmptyString)
{
diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs
index 39acd0deb5a9f1..91dff62fa1fbc1 100644
--- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs
+++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs
@@ -209,6 +209,10 @@ public override Type GetEnumUnderlyingType()
return _underlyingType;
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:ReflectionToDynamicallyAccessedMembers",
+ Justification = "For instance members with MethodImplOptions.InternalCall, the linker preserves all fields of the declaring type. " +
+ "The _tb field has DynamicallyAccessedMembersAttribute requirements, but the field access is safe because " +
+ "Reflection.Emit is not subject to trimming.")]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern void setup_enum_type(Type t);
diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs
index 26bca9f69f234c..f2b83fbc7684fc 100644
--- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs
+++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs
@@ -752,6 +752,10 @@ public ConstructorBuilder DefineTypeInitializer()
null);
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2110:ReflectionToDynamicallyAccessedMembers",
+ Justification = "For instance member internal calls, the linker preserves all fields of the declaring type. " +
+ "The parent and created fields have DynamicallyAccessedMembersAttribute requirements, but creating the runtime class is safe " +
+ "because the annotations fully preserve the parent type, and the type created via Reflection.Emit is not subject to trimming.")]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern TypeInfo create_runtime_class();