Aspnetcore: [Blazor] `InputNumber` does not support the type 'System.Int64'

Created on 17 Aug 2019  路  4Comments  路  Source: dotnet/aspnetcore

If you believe you have an issue that affects the security of the platform please do NOT create an issue and instead email your issue details to [email protected]. Your report may be eligible for our bug bounty but ONLY if it is reported through email.

Describe the bug

Firstly, a big thank you for all of the work that everyone has put into the Blazor framework.

The InputNumber component does not support binding to properties of the long data type.

To Reproduce

<EditForm Model="@Model">
    <DataAnnotationsValidator/>
    <ValidationSummary/>

    <div class="form-group">
        <label for="name">Name</label>
        <InputText class="form-control" id="name" @bind-Value="@Model.Name"/>
        <ValidationMessage For="@(() => Model.Name)"/>
    </div>

    <div class="form-group">
        <label for="code">Code</label>
        <InputNumber class="form-control" id="code" @bind-Value="@Model.Code"/>
        <ValidationMessage For="@(() => Model.Code)"/>
    </div>

    <button class="btn btn-primary mdi mdi-content-save" type="submit">Save</button>
</EditForm>

@code
{

    private Product Model { get; set; } = new Product();

    public class Product
    {
        [Required] public string Name { get; set; }

        [Required] public long Code { get; set; }
    }

}

System.InvalidOperationException: The type 'System.Int64' is not a supported numeric type.

Expected behavior

Based on this comment, the InputNumber component should support binding to the long type.

Looking through the code, the issue appears to be caused by the checks in this if statement.

If this is the case, then I am happy to create a fork to add targetType == typeof(long).

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.
Include the output of dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview8-013656
 Commit:    8bf06ffc8d

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18956
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\

Host (useful for support):
  Version: 3.0.0-preview8-28405-07
  Commit:  d01b2fb7bc

.NET Core SDKs installed:
  3.0.100-preview8-013656 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.0.0-preview8.19405.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Done area-blazor bug

All 4 comments

@tnc1997 thanks for the issue report. We'll track fixing this for the next Blazor release.

I ran into this issue as well and checked the source code. Seems that it was simply missed in the type checking.

if (targetType == typeof(int) ||
                targetType == typeof(float) ||
                targetType == typeof(double) ||
                targetType == typeof(decimal))
            {
                _stepAttributeValue = "any";
            }

because the converter exists in the case statement.

case long @long:
                    return BindConverter.FormatValue(@long, CultureInfo.InvariantCulture);

Also I have noticed that several of the input components have some kind of issue with bindings different types. Would it not be better/easier to consolidate the value conversion into the base class and let it handle it for all the inputs?

Any reason why this isn't making it into 3.0?

I almost forgot, thanks @tnc1997! Your investigation made things a lot easier here.

Was this page helpful?
0 / 5 - 0 ratings