Skip to content

EventCallback<T> Error cannot convert from 'method group' to 'EventCallback' #10077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
drinkwater99 opened this issue May 8, 2019 · 5 comments · Fixed by #10730
Closed

EventCallback<T> Error cannot convert from 'method group' to 'EventCallback' #10077

drinkwater99 opened this issue May 8, 2019 · 5 comments · Fixed by #10730
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@drinkwater99
Copy link

Describe the bug

Using the following two components, the compiler emits an error in the Parent component in the OnSelect event parameter.

Error cannot convert from 'method group' to 'EventCallback'

<Child Data="@Data" OnSelect="@OnSelect">
</Child>

Is this an issue or I am doing this wrong ?

To Reproduce

@*Parent.razor*@

@page "/Parent"

<div>
    <Child Data="@Data" OnSelect="@OnSelect">
    </Child>
</div>

@functions {
    List<Item> Data = new List<Item>();

    private void OnSelect(Item item)
    {        
    }
}
@*Child.razor*@

@typeparam TData

<div>
    @foreach (var item in Data)
    {
        <button onclick="@(() => OnSelect.InvokeAsync(item))"></button>
    }
</div>

@functions {
    [Parameter]
    public IEnumerable<TData> Data { get; set; }

    [Parameter]
    private EventCallback<TData> OnSelect { get; set; }
}
// Item.cs
public class Item
{
     public Item()
     {

     }
}
@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 8, 2019
@enetstudio
Copy link

shouldn't you use async before () => OnSelect.InvokeAsync(item) ?
shouldn't you define Task instead of void with the definition of OnSelect ?
Would you try Func<TData, Task> instead of EventCallback ?

@drinkwater99
Copy link
Author

Using async and Task does not change anything - the error remains.

The only way I am able to make it work is by doing the following in the Parent component event handler :

<Child Data="@Data" OnSelect2="@((Item item) => { OnSelect(item); })"></Child>

instead of :

<Child Data="@Data" OnSelect="@OnSelect">

Seems kind of strange to me that it would need to be done that way though.

@stsrki
Copy link
Contributor

stsrki commented May 9, 2019

@drinkwater99 You're seeing this error because of generics(typeparam) with EventCallback, It's not supported yet.
I have also reported that bug months ago and still waiting. see #8385

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@rynowak rynowak added the bug This issue describes a behavior which is not expected - a bug. label Jun 5, 2019
@rynowak rynowak self-assigned this Jun 5, 2019
@rynowak rynowak added this to the 3.0.0-preview7 milestone Jun 5, 2019
@rynowak
Copy link
Member

rynowak commented Jun 5, 2019

This has been added in preview 7 - #10730
Note that preview 6 is the next release so you will have to wait a few weeks.

@MichaelPeter
Copy link

MichaelPeter commented Jul 26, 2019

Hey I have Installed Preview 7 but I still get this error, shouldn't this be fixed?

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants