You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is related to the DefaultValueAttribute, the Enums and the PropertyDescriptor class. The issue is in the static Enum.ToObject method. In order to observe the issue, it is necessary to use an integer as a default value of an enumeration. The code below easily reproduces it:
using System.ComponentModel;using System.Windows.Forms;namespaceEnumDefaultValueIssue{publicpartialclassForm1:Form{publicForm1(){
InitializeComponent();varbtn=new MyButton();varproperties= TypeDescriptor.GetProperties(btn);varprop= properties["Dock"];// Crashes when calling ShouldSerializeValue on the PropertyDescriptorvarshouldSerialize= prop.ShouldSerializeValue(btn);}}publicclassMyButton{//[DefaultValueAttribute(DockStyle.None)] //No crash[DefaultValueAttribute(0)]// CrashpublicDockStyleDock{get;set;}}}
I`ve tested with the latest .NET 5.0 - 5.0.100-preview.8.20417.9, the issue is likely to be observed with other .NET Core runtimes. The same setup is working well in the full .NET framework.
Workaround:
Don't use the underlying integer type in the DefaultValueAttribute but rather the real enum member.
The text was updated successfully, but these errors were encountered:
Moving to ComponentModel given the issue seems to be with the way that ReflectPropertyDescriptor is trying to get the default value of the object. This is not a regression, as I can at least repro with 3.1
It is related to the
DefaultValueAttribute
, theEnums
and thePropertyDescriptor
class. The issue is in the staticEnum.ToObject
method. In order to observe the issue, it is necessary to use an integer as a default value of an enumeration. The code below easily reproduces it:I`ve tested with the latest .NET 5.0 - 5.0.100-preview.8.20417.9, the issue is likely to be observed with other .NET Core runtimes. The same setup is working well in the full .NET framework.
Workaround:
Don't use the underlying integer type in the
DefaultValueAttribute
but rather the real enum member.The text was updated successfully, but these errors were encountered: