Skip to content

Blazor can not compile generic-typed component with generic array parameter #15014

@xiety

Description

@xiety

Describe the bug

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?)

To Reproduce

Component.razor

@typeparam TItem
@code {
    [Parameter]
    public TItem[] List { get; set; }
}

Page.razor

<Component TItem="System.Int32" List="new int[] { 1, 2, 3 }" />

Expected behavior

Compile without errors.

Actual behavior

Compilation error CS0246 in generated file:

__builder.AddAttribute(1, "List", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<TItem[]>());

Workaround

IReadOnlyList<TItem> works fine

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions