-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overflow exception on Numeric field when using up/down arrows to increment value #1567
Comments
Thank you for addressing this so swiftly! After viewing your solution I came up with this to cover all the native number types for .NET 7 and above. I tested this code with float, byte, int, and decimal types. To summarize added 3 new private methods to handle step up/down for native number types in .NET >= 7.0 and a modification in UpdateValueWithStep() to uses these methods. For .NET < 7.0 or non number types process step up/down as it does currently.
|
Thanks @phantomkingx! You can submit pull request! |
Yes created PR #1570 |
Describe the bug
Overflow exception on Numeric field when using up/down arrows to increment value and the value overflows specific datatype.
To Reproduce
Steps to reproduce the behavior:
=========================================
@code{
byte value;
}
=========================================
Press the 'Run' button to use the modified code in the example. The example will reload with the Numeric field set to '0'.
Press the down arrow on the Numeric field and there will be a Blazor exception:
blazor.web.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Value was either too large or too small for an unsigned byte.
System.OverflowException: Value was either too large or too small for an unsigned byte.
at System.Number.ThrowOverflowExceptionByte
at System.Decimal.ToByte(Decimal value)
at System.Convert.ToByte(Decimal value)
at System.Decimal.System.IConvertible.ToByte(IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
at Radzen.ConvertType.ChangeType(Object value, Type type)
at Radzen.Blazor.RadzenNumeric
1[[System.Byte, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ConvertFromDecimal(Nullable
1 input)at Radzen.Blazor.RadzenNumeric`1.d__12[[System.Byte, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
Expected behavior
It would be ideal to avoid generating an exception on the page. It is possible to use Min/Max properties to avoid the exception for this particular example, however Min/Max uses the decimal datatype and an overflow exception will occur if the field is set to decimal MaxValue (79228162514264337593543950335) and the up arrow is pressed:
Additional context
Although this is somewhat of an edge case I'm not clear if there is currently a way to prevent this exception from happening.
A possible fix to this could be for the Radzen field to catch the overflow exception while ensuring no state has changed on the field. A new callback property 'Overflow' would allow for the option to handle the overflow with a user message or some other action. If we don't want this to be a breaking change incase someone expects the Blazor exception then check if the 'Overflow' property is set and rethrow the original exception if it is not.
The text was updated successfully, but these errors were encountered: