Skip to content

Commit a35aff7

Browse files
[main] Update dependencies from mono/linker (#56593)
* Update linker warning suppressions dotnet/linker#2145 warns when accessing members annotated with DynamicallyAccessedMembers using reflection, and dotnet/linker#2162 updates the warning origin of warnings for DynamicallyAccessedMembers on types. This adds suppressions for the new warnings. * Add windows-specific suppressions * Update dependencies from https://github.com/mono/linker build 20210729.2 Microsoft.NET.ILLink.Tasks From Version 6.0.100-preview.6.21378.1 -> To Version 6.0.100-preview.6.21379.2 * Fix failures and address feedback - Annotate mono's EnumBuilder and TypeBuilder - Add (non-unique) readable short names to the warning codes * Update dependencies from https://github.com/mono/linker build 20210730.2 Microsoft.NET.ILLink.Tasks From Version 6.0.100-preview.6.21378.1 -> To Version 6.0.100-preview.6.21380.2 * Suppress IL2111 * Update dependencies from https://github.com/mono/linker build 20210802.2 Microsoft.NET.ILLink.Tasks From Version 6.0.100-preview.6.21378.1 -> To Version 6.0.100-preview.6.21402.2 * Feedback - Suppress IL2111 in trimming tests - Remove unnecessary DynamicDependency - Fix indentation * Update readable warning names Co-authored-by: Sven Boemer <sbomer@gmail.com> Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
1 parent a33ea98 commit a35aff7

File tree

20 files changed

+159
-37
lines changed

20 files changed

+159
-37
lines changed

eng/Version.Details.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@
186186
<Uri>https://github.com/dotnet/runtime</Uri>
187187
<Sha>95863758cd16c345d0b8fca067d5db5d6901e498</Sha>
188188
</Dependency>
189-
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="6.0.100-preview.6.21378.1">
189+
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="6.0.100-preview.6.21402.2">
190190
<Uri>https://github.com/mono/linker</Uri>
191-
<Sha>0cb9250a903cfc90cbac602ed79c0cbc588d8d3f</Sha>
191+
<Sha>ae18468b8712503aee67911228dd921601bd423a</Sha>
192192
</Dependency>
193193
<Dependency Name="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.21373.1">
194194
<Uri>https://github.com/dotnet/xharness</Uri>

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
<!-- Docs -->
167167
<MicrosoftPrivateIntellisenseVersion>5.0.0-preview-20201009.2</MicrosoftPrivateIntellisenseVersion>
168168
<!-- ILLink -->
169-
<MicrosoftNETILLinkTasksVersion>6.0.100-preview.6.21378.1</MicrosoftNETILLinkTasksVersion>
169+
<MicrosoftNETILLinkTasksVersion>6.0.100-preview.6.21402.2</MicrosoftNETILLinkTasksVersion>
170170
<MicrosoftNETILLinkAnalyzerPackageVersion>$(MicrosoftNETILLinkTasksVersion)</MicrosoftNETILLinkAnalyzerPackageVersion>
171171
<!-- ICU -->
172172
<MicrosoftNETCoreRuntimeICUTransportVersion>6.0.0-rc.1.21369.1</MicrosoftNETCoreRuntimeICUTransportVersion>

eng/testing/linker/SupportFiles/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<!-- Suppress analyzer and linker warnings as these are tests -->
1818
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
1919
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
20+
<!-- Can be removed when SDK update picks up https://github.com/dotnet/sdk/pull/18655. -->
21+
<NoWarn>$(NoWarn);IL2111</NoWarn>
2022
</PropertyGroup>
2123

2224
<ItemGroup>

eng/testing/tests.mobile.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<PublishTrimmed>true</PublishTrimmed>
1818
<!-- Suppress linker warnings as these are tests -->
1919
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
20+
<!-- Can be removed when SDK update picks up https://github.com/dotnet/sdk/pull/18655. -->
21+
<NoWarn>$(NoWarn);IL2111</NoWarn>
2022
<!-- https://github.com/dotnet/sdk/issues/18581 tracks needing to set 2 properties to disable warnings. -->
2123
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
2224

src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,10 @@ private sealed class LicenseClassFactory : IClassFactory2
523523
private readonly LicenseInteropProxy _licenseProxy = new LicenseInteropProxy();
524524
private readonly Guid _classId;
525525

526-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
526+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicConstructors)]
527527
private readonly Type _classType;
528528

529-
public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type classType)
529+
public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicConstructors)] Type classType)
530530
{
531531
_classId = clsid;
532532
_classType = classType;
@@ -627,6 +627,9 @@ internal sealed class LicenseInteropProxy
627627
private object? _licContext;
628628
private Type? _targetRcwType;
629629

630+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
631+
Justification = "The type parameter to LicenseManager.CreateWithContext method has PublicConstructors annotation. We only invoke this method" +
632+
"from AllocateAndValidateLicense which annotates the value passed in with the same annotation.")]
630633
public LicenseInteropProxy()
631634
{
632635
Type licManager = Type.GetType("System.ComponentModel.LicenseManager, System.ComponentModel.TypeConverter", throwOnError: true)!;
@@ -742,7 +745,7 @@ public string RequestLicKey(Type type)
742745
// If we are being entered because of a call to ICF::CreateInstanceLic(),
743746
// "isDesignTime" will be "false" and "key" will point to a non-null
744747
// license key.
745-
public object AllocateAndValidateLicense(Type type, string? key, bool isDesignTime)
748+
public object AllocateAndValidateLicense([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, string? key, bool isDesignTime)
746749
{
747750
object?[] parameters;
748751
object? licContext;

src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/IDOBinder.vb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,8 @@ Namespace Microsoft.VisualBasic.CompilerServices
824824

825825
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
826826
Justification:=IDOBinder.SuppressionJustification)>
827+
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
828+
Justification:=IDOBinder.SuppressionJustification)>
827829
Public Overrides Function FallbackConvert(
828830
ByVal target As DynamicMetaObject,
829831
ByVal errorSuggestion As DynamicMetaObject) As DynamicMetaObject

src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
namespace System.Data.Common
1414
{
15-
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
16-
// 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.
17-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
18-
Justification = "The use of GetType preserves members with RequiresUnreferencedCode, but the GetType callsites either "
15+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode",
16+
Justification = "The use of GetType preserves ICustomTypeDescriptor members with RequiresUnreferencedCode, but the GetType callsites either "
1917
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
2018
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
2119
public class DbConnectionStringBuilder : IDictionary, ICustomTypeDescriptor
@@ -393,6 +391,9 @@ internal Attribute[] GetAttributesFromCollection(AttributeCollection collection)
393391
return attributes;
394392
}
395393

394+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
395+
Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
396+
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
396397
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
397398
private PropertyDescriptorCollection GetProperties()
398399
{
@@ -419,6 +420,9 @@ private PropertyDescriptorCollection GetProperties()
419420
return propertyDescriptors;
420421
}
421422

423+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
424+
Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
425+
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
422426
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
423427
protected virtual void GetProperties(Hashtable propertyDescriptors)
424428
{
@@ -526,6 +530,9 @@ protected virtual void GetProperties(Hashtable propertyDescriptors)
526530
}
527531
}
528532

533+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
534+
Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
535+
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
529536
[RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
530537
private PropertyDescriptorCollection GetProperties(Attribute[]? attributes)
531538
{

src/libraries/System.Data.Common/src/System/Data/DataSet.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ namespace System.Data
3030
[XmlSchemaProvider(nameof(GetDataSetSchema))]
3131
[XmlRoot(nameof(DataSet))]
3232
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
33-
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
34-
// 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.
35-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
36-
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.")]
3733
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] // needed by Clone() to preserve derived ctors
3834
public class DataSet : MarshalByValueComponent, IListSource, IXmlSerializable, ISupportInitializeNotification, ISerializable
3935
{
@@ -231,11 +227,15 @@ protected void GetSerializationData(SerializationInfo info, StreamingContext con
231227

232228
// Deserialize all the tables schema and data of the dataset from binary/xml stream.
233229
[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)]
230+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
231+
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.")]
234232
protected DataSet(SerializationInfo info, StreamingContext context) : this(info, context, true)
235233
{
236234
}
237235

238236
[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)]
237+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
238+
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.")]
239239
protected DataSet(SerializationInfo info, StreamingContext context, bool ConstructSchema) : this()
240240
{
241241
SerializationFormat remotingFormat = SerializationFormat.Xml;

src/libraries/System.Data.Common/src/System/Data/DataTable.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ namespace System.Data
3131
[XmlSchemaProvider(nameof(GetDataTableSchema))]
3232
[Serializable]
3333
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
34-
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
35-
// 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.
36-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
37-
Justification = "CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
3834
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
3935
public class DataTable : MarshalByValueComponent, IListSource, ISupportInitializeNotification, ISerializable, IXmlSerializable
4036
{
@@ -196,6 +192,8 @@ public DataTable(string? tableName, string? tableNamespace) : this(tableName)
196192
}
197193

198194
// Deserialize the table from binary/xml stream.
195+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
196+
Justification = "CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
199197
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
200198
protected DataTable(SerializationInfo info, StreamingContext context) : this()
201199
{

src/libraries/System.Data.Common/src/System/Data/DataTableReader.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,14 @@ internal static DataTable GetSchemaTableFromDataTable(DataTable table)
737737
DataColumn ColumnSize = new DataColumn(SchemaTableColumn.ColumnSize, typeof(int));
738738
DataColumn NumericPrecision = new DataColumn(SchemaTableColumn.NumericPrecision, typeof(short));
739739
DataColumn NumericScale = new DataColumn(SchemaTableColumn.NumericScale, typeof(short));
740-
DataColumn DataType = new DataColumn(SchemaTableColumn.DataType, typeof(Type));
740+
DataColumn DataType = GetSystemTypeDataColumn();
741+
742+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
743+
Justification = "The problem is Type.TypeInitializer which requires constructors on the Type instance." +
744+
"In this case the TypeInitializer property is not accessed dynamically.")]
745+
static DataColumn GetSystemTypeDataColumn() =>
746+
new DataColumn(SchemaTableColumn.DataType, typeof(Type));
747+
741748
DataColumn ProviderType = new DataColumn(SchemaTableColumn.ProviderType, typeof(int));
742749
DataColumn IsLong = new DataColumn(SchemaTableColumn.IsLong, typeof(bool));
743750
DataColumn AllowDBNull = new DataColumn(SchemaTableColumn.AllowDBNull, typeof(bool));

src/libraries/System.Data.Common/src/System/Data/TypedTableBase.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ namespace System.Data
1212
/// This is the generic base class for TypedDataSet
1313
/// </summary>
1414
[Serializable]
15-
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
16-
// 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.
17-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
18-
Justification = "DataTable.CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
1915
public abstract class TypedTableBase<T> : DataTable, IEnumerable<T> where T : DataRow
2016
{
2117

@@ -32,6 +28,8 @@ protected TypedTableBase() : base() { }
3228
/// </summary>
3329
/// <param name="info">SerializationInfo containing data to construct the object.</param>
3430
/// <param name="context">The streaming context for the object being deserialized.</param>
31+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:ReflectionToRequiresUnreferencedCode",
32+
Justification = "DataTable.CreateInstance's use of GetType uses only the parameterless constructor, not this serialization related constructor.")]
3533
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
3634
protected TypedTableBase(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
3735
: base(info, context) { }

src/libraries/System.Data.OleDb/src/ILLink/ILLink.Suppressions.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,10 @@
9797
<property name="Scope">member</property>
9898
<property name="Target">M:System.Data.OleDb.OleDbDataReader.GetFieldType(System.Int32)</property>
9999
</attribute>
100-
</assembly>
100+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
101+
<argument>ILLink</argument>
102+
<argument>IL2111</argument>
103+
<property name="Scope">member</property>
104+
<property name="Target">M:System.Data.OleDb.OleDbDataReader.BuildSchemaTable(MetaData[])</property>
105+
</attribute> </assembly>
101106
</linker>

0 commit comments

Comments
 (0)