-
Notifications
You must be signed in to change notification settings - Fork 10.3k
error CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback' #12226
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
Comments
A workaround (maybe even the correct way):
|
I agree that this still seems like an issue as creating verbose markup when handling events (without databinding). Take the
|
From what I can tell, the problem is that the compiler does not use the the generic type parameter for type inference in method calls. Here's a fairly trivial example: public void Foo()
{
Tester<int>(2, TestAction);
// This fails complaining about type inference
Tester<int>(2, CreateDelegate(TestAction));
}
public void TestAction(int x) { }
public void Tester<T>(T value, Action<T> input) { }
public static Action<T> CreateDelegate<T>(Action<T> action) => action; We effectively get the same code when we code-gen a Razor file like this: <InputSelect ValueChanged="ChangedInt" />
@code {
public void ChangedInt(int value)
{
}
} using Microsoft.AspNetCore.Components;
namespace razor1.Pages
{
public class Index : Microsoft.AspNetCore.Components.ComponentBase
{
protected override void BuildRenderTree(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder)
{
__Blazor.razor1.Pages.Index.TypeInference.CreateInputSelect_0(builder, 0, 1, Microsoft.AspNetCore.Components.EventCallback.Factory.Create(this,
ChangedInt
));
}
public void ChangedInt(int value)
{
}
}
}
namespace __Blazor.razor1.Pages.Index
{
internal static class TypeInference
{
public static void CreateInputSelect_0<T>(global::Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, global::Microsoft.AspNetCore.Components.EventCallback<T> __arg0)
{
builder.OpenComponent<global::Microsoft.AspNetCore.Components.Forms.InputSelect<T>>(seq);
builder.AddAttribute(__seq0, "ValueChanged", __arg0);
builder.CloseComponent();
}
}
} The compiler fails the type inferrence, picks the wrong overload for From playing around, one of the ways to solve this would be to modify the code in Workarounds that have been pointed out by others in the thread that work:
(I filed an issue to do a pass over blazor input elements to consider renaming
|
Thanks for contacting us, @gurunathancs1991. |
EdCharbeneau commented on 23 Jul wrote: but this solution is not working with Current value: @form.MyProperty 0 100 200 300@code {
} |
Sorry my mistake: |
Description:
When using
EventCallBack<T>
, I countered an issue abouterror CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback'
I have checked other github blogs which related to this, mostly reported that, this has been fixed in preview 7 version. Right now, i have tested with preview 7 build but could not get resolve it.
Here the link which i checked earlier.
#10077
#8385
#10730
#10077
Whether any syntax changes required to resolve in preview 7 version?
Screenshot:

Please find my component structure:
Rendering Page [Index razor page]
MyGenComponent.razor
Events.razor
GenericEvents.razor
NonGenericEvents.razor
To Reproduce
Clone this Github repository and run the application
https://github.com/gurunathancs1991/BlazorGenericEvents
We are also expecting the solution for this thread too
#12116
Additional context
The text was updated successfully, but these errors were encountered: