Skip to content
Merged
Prev Previous commit
Update readable warning names
  • Loading branch information
sbomer committed Aug 3, 2021
commit b96ed81b47427f22fa42512da0fd961b9ae30702
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ internal sealed class LicenseInteropProxy
private object? _licContext;
private Type? _targetRcwType;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers",
[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.")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay for extra validation. Caught a bug here...

public LicenseInteropProxy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ Namespace Microsoft.VisualBasic.CompilerServices

<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification:=IDOBinder.SuppressionJustification)>
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers",
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers",
Justification:=IDOBinder.SuppressionJustification)>
Public Overrides Function FallbackConvert(
ByVal target As DynamicMetaObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace System.Data.Common
{
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode",
[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)]
Expand Down Expand Up @@ -391,7 +391,7 @@ internal Attribute[] GetAttributesFromCollection(AttributeCollection collection)
return attributes;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode",
[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.")]
Expand Down Expand Up @@ -420,7 +420,7 @@ private PropertyDescriptorCollection GetProperties()
return propertyDescriptors;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode",
[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.")]
Expand Down Expand Up @@ -530,7 +530,7 @@ protected virtual void GetProperties(Hashtable propertyDescriptors)
}
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode",
[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.")]
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Data.Common/src/System/Data/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ 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:RequiresUnreferencedCode",
[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:RequiresUnreferencedCode",
[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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public DataTable(string? tableName, string? tableNamespace) : this(tableName)
}

// Deserialize the table from binary/xml stream.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode",
[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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ internal static DataTable GetSchemaTableFromDataTable(DataTable table)
DataColumn NumericScale = new DataColumn(SchemaTableColumn.NumericScale, typeof(short));
DataColumn DataType = GetSystemTypeDataColumn();

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:RequiresDynamicallyAccessedMembers",
[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() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected TypedTableBase() : base() { }
/// </summary>
/// <param name="info">SerializationInfo containing data to construct the object.</param>
/// <param name="context">The streaming context for the object being deserialized.</param>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode",
[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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ namespace System.Diagnostics
/// </summary>
[EventSource(Name = "Microsoft-Diagnostics-DiagnosticSource")]
// These suppressions can go away with https://github.com/mono/linker/issues/2175
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:RequiresUnreferencedCode",
[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. " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why DiagnosticSourceEventSource is getting warnings for OverrideEventProvider. If it is - why isn't all EventSource's getting this warning?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning is due to DAMT.All on EventSource, which ensures that GetType keeps everything on EventSource - in this case the nested type OverrideEventProvider, plus its base type EventProvider, which has a delegate, which has some RUC methods: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Delegate.cs#L45.

Ideally we wouldn't produce this warning for derived types, and it would show up only on EventSource, but we haven't taught the linker about this (see dotnet/linker#2175).

In theory this should currently show up on every derived EventSource... but I believe due to dotnet/linker#2159 we only produce a warning for the first one that we see. :( /cc @LakshanF

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only produce a warning for the first one that we see. :(

Oh no, that doesn't sound like a great situation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds bad - could it lead to us getting warnings from CoreLib when trimming apps? For some reason linker will see this on another EventSource and will warn there - and it's not suppressed there. We need to fix this if that's the case.

"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:RequiresDynamicallyAccessedMembers",
[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 " +
Expand Down Expand Up @@ -1024,7 +1024,7 @@ private void Dispose()
}
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode",
[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)]
Expand Down Expand Up @@ -1108,7 +1108,7 @@ 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:RequiresUnreferencedCode",
[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)]
Expand Down Expand Up @@ -1206,7 +1206,7 @@ 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")
/// </summary>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode",
[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)]
Expand Down Expand Up @@ -1260,7 +1260,7 @@ 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.
/// </summary>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode",
[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)]
Expand Down Expand Up @@ -1306,7 +1306,7 @@ public PropertyFetch(Type? type)
/// <summary>
/// Create a property fetcher for a propertyName
/// </summary>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112:RequiresUnreferencedCode",
[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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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:RequiresDynamicallyAccessedMembers",
[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)
Expand Down
Loading