Cannot cast string to Boolean #34816
Labels
area-blazor
Includes: Blazor, Razor Components
bug
This issue describes a behavior which is not expected - a bug.
Done
This issue has been fixed
Milestone
In Blazor, having an input group with Boolean type, throws an exception. This is the setup:
<InputRadio TValue="bool" Value="true" />
generates :
<input type="radio" name="78ab199033a74bc0be851de4fcf8e64a" value="True">
Following exception is thrown:
Error: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Boolean'. at Microsoft.AspNetCore.Components.BindConverter.ConvertToBoolCore(Object obj, CultureInfo culture, Boolean& value) in Microsoft.AspNetCore.Components.dll:token 0x600003a+0x0 at Microsoft.AspNetCore.Components.BindConverter.TryConvertTo[T](Object obj, CultureInfo culture, T& value) in Microsoft.AspNetCore.Components.dll:token 0x6000066+0x0 at Microsoft.AspNetCore.Components.Forms.InputExtensions.TryParseSelectableValueFromString[TValue](InputBase
1 input, String value, TValue& result, String& validationErrorMessage) in Microsoft.AspNetCore.Components.Web.dll:token 0x6000171+0x0at Microsoft.AspNetCore.Components.Forms.InputRadioGroup
1.TryParseValueFromString(String value, TValue& result, String& validationErrorMessage) in Microsoft.AspNetCore.Components.Web.dll:token 0x60001e8+0x0 at Microsoft.AspNetCore.Components.Forms.InputBase
1.set_CurrentValueAsString(String value) in Microsoft.AspNetCore.Components.Web.dll:token 0x6000152+0x3aat Microsoft.AspNetCore.Components.Forms.InputRadioGroup
1.<OnParametersSet>b__14_0(String __value) in Microsoft.AspNetCore.Components.Web.dll:token 0x60001ea+0x0 at Microsoft.AspNetCore.Components.EventCallbackFactoryBinderExtensions.<>c__DisplayClass24_0
1.b__0(ChangeEventArgs e) in Microsoft.AspNetCore.Components.dll:token 0x600037a+0x2c--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) in Microsoft.AspNetCore.Components.dll:token 0x60000a2+0x65
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState) in Microsoft.AspNetCore.Components.dll:token 0x600023e+0x65`
Related code expects a boolean already not a string so it crashes:
aspnetcore/src/Components/Components/src/BindConverter.cs
Lines 564 to 569 in 8b30d86
The text was updated successfully, but these errors were encountered: