Compiler error when using generic array parameter.
If there is no type parameter:
error RZ10001: The type of component 'Component' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'TItem'.
If type parameter is specified:
error CS0246: The type or namespace name 'TItem' could not be found (are you missing a using directive or an assembly reference?)
Component.razor
@typeparam TItem
@code {
[Parameter]
public TItem[] List { get; set; }
}
Page.razor
<Component TItem="System.Int32" List="new int[] { 1, 2, 3 }" />
Compile without errors.
Compilation error CS0246 in generated file:
__builder.AddAttribute(1, "List", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<TItem[]>());
IReadOnlyList<TItem> works fine
Thanks for contacting us, @xiety.
We will look into this post 3.1 milestone. Your workaround looks good for now.
i have a question
can do something like this...
<input @bind="Value"/>
@code{
[Parameter]
public object Value {get; set;}
}
@rynowak is this by-design?
Would be great if all those generic issues in Blazor would be fixed soon. It's a sad thing that these bugs will probably remain in .NET 5.0 RTM. Most of the issues are tagged as affected-very-few 馃槥
I have the same issue in .NET 5.