Skip to content

Blazor can't use EventCallback with array TypeParam value  #7476

Open
@omuleanu

Description

I've isolated my issue to a small bit of code, having a component like this:

MyArrValComp.razor

@typeparam TKey
@code {
    [Parameter]
    public TKey[] Value { get; set; }

    [Parameter]
    public EventCallback<TKey[]> ValueChanged { get; set; }
}

I call the component like in Index.razor like this:

<MyArrValComp @bind-Value="val1" TKey="int"/>
@code
{
    private int[] val1 = new []{ 1, 2, 3 };
}

and it won't compile, it will give misleading error messages like this:
The type or namespace name 'TKey' could not be found (are you missing a using directive ... Index.razor.g.cs
The type or namespace name 'TKey' could not be found (are you missing a using ... Index.razor

after experimentation I realized that Arrays won't work with EventCallback I need to use IEnumerable<T> instead, that fixed it.


  1. so the error messages are definitely misleading,
  2. also not sure if you're aware about this issue, I haven't noticed in the docs saying that we can't use arrays with EventCallback
  3. is it possible to bind to any collection, I was hoping since Value and ValueChanged are IEnumerable<T> I'll be able to bind to any collection (including T[] ) but no, it only accepts IEnumerable<T> ?

Metadata

Assignees

No one assigned

    Labels

    area-compilerUmbrella for all compiler issuesbugSomething isn't workinguntriaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions