From 52e2348aa350f6e516a06f9fc97475268907e2fd Mon Sep 17 00:00:00 2001 From: Qiaoxi Guo <28090444+breadtitor@users.noreply.github.com> Date: Sat, 15 Aug 2026 19:49:02 -0600 Subject: [PATCH 1/2] Fix Image dimension default value metadata The Width and Height properties are integers, but their DefaultValue attributes used false. Use zero and cover both properties through TypeDescriptor metadata. Fix dotnet/runtime#126265 --- .../src/System/Drawing/Image.cs | 4 ++-- .../tests/System/Drawing/ImageTests.cs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/System.Drawing.Common/src/System/Drawing/Image.cs b/src/System.Drawing.Common/src/System/Drawing/Image.cs index b9c855e7d04..79c89e25fcd 100644 --- a/src/System.Drawing.Common/src/System/Drawing/Image.cs +++ b/src/System.Drawing.Common/src/System/Drawing/Image.cs @@ -423,7 +423,7 @@ public SizeF PhysicalDimension /// /// Gets the width of this . /// - [DefaultValue(false)] + [DefaultValue(0)] [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public int Width @@ -440,7 +440,7 @@ public int Width /// /// Gets the height of this . /// - [DefaultValue(false)] + [DefaultValue(0)] [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public int Height diff --git a/src/System.Drawing.Common/tests/System/Drawing/ImageTests.cs b/src/System.Drawing.Common/tests/System/Drawing/ImageTests.cs index 16e0bd70193..c385d723eb8 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/ImageTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/ImageTests.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.ComponentModel; using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Text; @@ -19,6 +20,19 @@ public class ImageTests private const int PropertyTagTypeASCII = 2; private const int PropertyTagTypeShort = 3; + [Theory] + [InlineData(nameof(Image.Width))] + [InlineData(nameof(Image.Height))] + public void ImageDimensionProperty_DefaultValueIsZero(string propertyName) + { + PropertyDescriptor? property = TypeDescriptor.GetProperties(typeof(Image))[propertyName]; + Assert.NotNull(property); + + DefaultValueAttribute defaultValue = Assert.IsType( + property.Attributes[typeof(DefaultValueAttribute)]); + Assert.Equal(0, defaultValue.Value); + } + [Fact] public void PropertyIdList_GetBitmapJpg_Success() { From d052aa884635b043bc692aaba710f91b00e5ef75 Mon Sep 17 00:00:00 2001 From: Qiaoxi Guo <28090444+breadtitor@users.noreply.github.com> Date: Sun, 16 Aug 2026 01:25:14 -0600 Subject: [PATCH 2/2] Suppress intentional Image metadata compatibility changes --- .../src/CompatibilitySuppressions.xml | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/System.Drawing.Common/src/CompatibilitySuppressions.xml b/src/System.Drawing.Common/src/CompatibilitySuppressions.xml index f05c3bdda4e..87049cd61f1 100644 --- a/src/System.Drawing.Common/src/CompatibilitySuppressions.xml +++ b/src/System.Drawing.Common/src/CompatibilitySuppressions.xml @@ -25,6 +25,32 @@ lib/netstandard2.0/System.Drawing.Common.dll lib/net462/System.Drawing.Common.dll + + CP0015 + P:System.Drawing.Image.Height:[T:System.ComponentModel.DefaultValueAttribute] + lib/net10.0/System.Drawing.Common.dll + lib/net10.0/System.Drawing.Common.dll + true + + + CP0015 + P:System.Drawing.Image.Width:[T:System.ComponentModel.DefaultValueAttribute] + lib/net10.0/System.Drawing.Common.dll + lib/net10.0/System.Drawing.Common.dll + true + + + CP0015 + P:System.Drawing.Image.Height:[T:System.ComponentModel.DefaultValueAttribute] + lib/netstandard2.0/System.Drawing.Common.dll + lib/net10.0/System.Drawing.Common.dll + + + CP0015 + P:System.Drawing.Image.Width:[T:System.ComponentModel.DefaultValueAttribute] + lib/netstandard2.0/System.Drawing.Common.dll + lib/net10.0/System.Drawing.Common.dll + CP0015 P:System.Drawing.Font.Name:[T:System.ComponentModel.EditorAttribute] @@ -67,4 +93,4 @@ lib/netstandard2.0/System.Drawing.Common.dll lib/net462/System.Drawing.Common.dll - \ No newline at end of file +