diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index 795297759344ecc38ff761234301f1e0bb762228..3ac90d7c6ed2473499897932bc0ecbd03166a4d2 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -347,6 +347,7 @@ public partial class FontConverter : System.ComponentModel.TypeConverter public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) { throw null; } public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext? context, System.Collections.IDictionary propertyValues) { throw null; } public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } + [Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of value cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext? context, object? value, System.Attribute[]? attributes) { throw null; } public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { throw null; } public sealed partial class FontNameConverter : System.ComponentModel.TypeConverter, System.IDisposable @@ -792,6 +793,7 @@ public partial class ImageConverter : System.ComponentModel.TypeConverter public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Type? destinationType) { throw null; } public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value) { throw null; } public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, System.Type destinationType) { throw null; } + [Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of value cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] public override System.ComponentModel.PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext? context, object? value, System.Attribute[]? attributes) { throw null; } public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext? context) { throw null; } } diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.csproj b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.csproj index 5d75861c9a563bdefacc3bd09d97f135d3cb9af5..8dbce3bef1d292b4123b0ebcf8a031f4b4cee350 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.csproj @@ -1,4 +1,4 @@ - + $(NetCoreAppCurrent);netcoreapp3.1;netstandard2.0;net461 true @@ -11,6 +11,9 @@ + + + diff --git a/src/libraries/System.Drawing.Common/src/ILLink/ILLink.Suppressions.xml b/src/libraries/System.Drawing.Common/src/ILLink/ILLink.Suppressions.xml index d19184f1f2224bd7f53265d133d3f60193920bdc..ec106d48670871c46e4b08dbb12522103d669879 100644 --- a/src/libraries/System.Drawing.Common/src/ILLink/ILLink.Suppressions.xml +++ b/src/libraries/System.Drawing.Common/src/ILLink/ILLink.Suppressions.xml @@ -5,49 +5,13 @@ ILLink IL2026 member - M:System.Drawing.BitmapSelector.DoesAssemblyHaveCustomAttribute(System.Reflection.Assembly,System.String) + M:System.Drawing.BitmapSelector.SameAssemblyOptIn(System.Reflection.Assembly) ILLink IL2026 member - M:System.Drawing.FontConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext,System.Globalization.CultureInfo,System.Object) - - - ILLink - IL2026 - member - M:System.Drawing.FontConverter.GetProperties(System.ComponentModel.ITypeDescriptorContext,System.Object,System.Attribute[]) - - - ILLink - IL2026 - member - M:System.Drawing.ImageConverter.GetProperties(System.ComponentModel.ITypeDescriptorContext,System.Object,System.Attribute[]) - - - ILLink - IL2026 - member - M:System.Drawing.Printing.MarginsConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext,System.Globalization.CultureInfo,System.Object) - - - ILLink - IL2026 - member - M:System.Drawing.Printing.MarginsConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext,System.Globalization.CultureInfo,System.Object,System.Type) - - - ILLink - IL2046 - member - M:System.Drawing.FontConverter.GetProperties(System.ComponentModel.ITypeDescriptorContext,System.Object,System.Attribute[]) - - - ILLink - IL2046 - member - M:System.Drawing.ImageConverter.GetProperties(System.ComponentModel.ITypeDescriptorContext,System.Object,System.Attribute[]) + M:System.Drawing.BitmapSelector.SatelliteAssemblyOptIn(System.Reflection.Assembly) ILLink @@ -115,17 +79,5 @@ member M:System.Drawing.SafeNativeMethods.Gdip.GdipSaveImageToStream(System.Runtime.InteropServices.HandleRef,Interop.Ole32.IStream,System.Guid@,System.Runtime.InteropServices.HandleRef) - - ILLink - IL2026 - member - M:System.Drawing.MacSupport.GetHwndDelegate - - - ILLink - IL2075 - member - M:System.Drawing.MacSupport.GetHwndDelegate - \ No newline at end of file diff --git a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj index ff076314c944dd145afeebbe4f993a96dd5f56c1..092ea6af165e9115f9c2b70651f86fd3a8277666 100644 --- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -1,4 +1,4 @@ - + $(DefineConstants);DRAWING_NAMESPACE true @@ -13,6 +13,10 @@ true SR.SystemDrawingCommon_PlatformNotSupported + + + + diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs index 956c1e5ded1deeb6a09adee22dc97b9877c07dc8..fcec880055ae2a14be2d3333bee39a1d61afbe63 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/BitmapSelector.cs @@ -3,6 +3,7 @@ namespace System.Drawing { + using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; @@ -84,6 +85,7 @@ public static string GetFileName(string originalPath) return stream; } + [RequiresUnreferencedCode("Calls Assembly.GetType which may be trimmed")] private static bool DoesAssemblyHaveCustomAttribute(Assembly assembly, string typeName) { return DoesAssemblyHaveCustomAttribute(assembly, assembly.GetType(typeName)); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs index f289f5549b8fba362c9c7b2d59c7b85418fa03fc..1ea09376a5cd0225da83c68e4b5274e77e341702 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs @@ -5,6 +5,7 @@ using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Drawing.Text; using System.Globalization; using System.Reflection; @@ -168,7 +169,7 @@ public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? c { try { - fontSize = (float)TypeDescriptor.GetConverter(typeof(float)).ConvertFromString(context, culture, unitTokens.size); + fontSize = (float)GetFloatConverter().ConvertFromString(context, culture, unitTokens.size); } catch { @@ -207,6 +208,10 @@ public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? c } return new Font(fontName, fontSize, fontStyle, units); + + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "TypeDescriptor.GetConverter is safe for primitive types.")] + static TypeConverter GetFloatConverter() => TypeDescriptor.GetConverter(typeof(float)); } private (string?, string?) ParseSizeTokens(string text, char separator) @@ -360,6 +365,7 @@ public override object CreateInstance(ITypeDescriptorContext? context, IDictiona public override bool GetCreateInstanceSupported(ITypeDescriptorContext? context) => true; + [RequiresUnreferencedCode("The Type of value cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] public override PropertyDescriptorCollection GetProperties( ITypeDescriptorContext? context, object? value, diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageConverter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageConverter.cs index 9836fbfc9a38d54d84da2700dd411e84e40b59bb..308df99d1d05f90f4599d8abc6f9b9dcd77c3006 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageConverter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageConverter.cs @@ -4,6 +4,7 @@ using System.Buffers.Binary; using System.ComponentModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Drawing.Imaging; using System.Globalization; using System.IO; @@ -102,6 +103,7 @@ public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? c return null; } + [RequiresUnreferencedCode("The Type of value cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object? value, Attribute[]? attributes) { return TypeDescriptor.GetProperties(typeof(Image), attributes); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/MarginsConverter.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/MarginsConverter.cs index 2431fde5eac15e24995c8eda5599231684b1b753..af6ac73329949fde5a8b9c699d923eb66e6a6989 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/MarginsConverter.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/MarginsConverter.cs @@ -64,7 +64,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina char sep = culture.TextInfo.ListSeparator[0]; string[] tokens = text.Split(sep); int[] values = new int[tokens.Length]; - TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int)); + TypeConverter intConverter = GetIntConverter(); for (int i = 0; i < values.Length; i++) { // Note: ConvertFromString will raise exception if value cannot be converted. @@ -80,6 +80,10 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina return base.ConvertFrom(context, culture, value); } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "TypeDescriptor.GetConverter is safe for primitive types.")] + private static TypeConverter GetIntConverter() => TypeDescriptor.GetConverter(typeof(int)); + /// /// Converts the given object to another type. The most common types to convert /// are to and from a string object. The default implementation will make a call @@ -102,7 +106,7 @@ public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? c culture = CultureInfo.CurrentCulture; } string sep = culture.TextInfo.ListSeparator + " "; - TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int)); + TypeConverter intConverter = GetIntConverter(); string[] args = new string[4]; int nArg = 0;