Skip to content

Blazor component with generics incorrectly invokes Func<T[]> that is a parameter #34711

@julian-altech

Description

@julian-altech

If a generic component has a parameter property:

@typeparam T

@code {
    [Parameter]
    public Func<T[]> GetItems { get; set; }
}

When you use the component the GetItems will cause a build fail with the error "The type or namespace name T could not be found" since it generates this code for the page:

__builder.OpenComponent<BlazorTest.Client.Shared.GenericComponent<string>>(0);
__builder.AddAttribute(1, "GetItems", new System.Func<T[]>(GetItems)

But there is no definition of T there as T is defined on the comonent, it should generate as string[] not T[]

To Reproduce

With the component above create the following page

@page "/"

<GenericComponent T="string" GetItems="GetItems" />

@code {
    string[] GetItems() => new[]
    {
        "Foo", "Bar"
    };
}

As soon as you try to compile it will fail

I have tested this on 6.0.0-preview.6.21355.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions