question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Razor components: Calling method with optional argument from event - "Error CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback'"

See original GitHub issue

I have a function in my component like this: private async Task LoadConferencesAsync(SearchFilter filter = null)

When I try to call it from an e.g. onclick event like this <MudIcon Icon="@Icons.Material.Filled.Refresh" @onclick="LoadConferencesAsync" />

I get this error: TTConfTool.UI/Conferences/Conferences.razor(66,66): Error CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback' (CS1503) (TTConfTool.UI)

Screen Shot 2021-03-06 at 17 34 53

Should it be possible to call methods with optional parameters?

Thanks!


.NET SDK (reflecting any global.json): Version: 6.0.100-preview.1.21103.13 Commit: b8a03527b2

Runtime Environment: OS Name: Mac OS X OS Version: 11.2 OS Platform: Darwin RID: osx.11.0-x64 Base Path: /usr/local/share/dotnet/sdk/6.0.100-preview.1.21103.13/

Host (useful for support): Version: 6.0.0-preview.1.21102.12 Commit: 9b2776d481

I am using Visual Studio Enterprise 2019 for Mac (Preview) Version 8.10 Preview (8.10 build 409)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mkArtakMSFTcommented, Mar 7, 2021

Thanks for contacting us. I’ve validated this and indeed having a method with an optional parameter will fail. You can, for now use an alternative syntax to workaround this:

<MudIcon @onclick="()=>LoadConferencesAsync()" />
0reactions
msftbot[bot]commented, Oct 21, 2021

We’ve moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot convert from 'method group' to 'EventCallback' - ...
I have a parent component and a child component with an event callback where I want it to pass back a type of...
Read more >
Cannot convert from method group to EventCallBack?
The code works fine when it the method is in the same file, but when I place it on another file it gives...
Read more >
Blazor - cannot convert from 'method group' to 'EventCallback'
The EventCallback uses a generic type and blazor cannot infer it if you don't pass the type to the component. This means that...
Read more >
Cannot convert void to EventCallback in Blazor
I had created a simple method in a Razor page in my Blazor app ... me the error “Argument 2: cannot convert from...
Read more >
cannot convert from 'method group' to 'EventCallback'
Hello, Can't understand what I'm doing wrong? Argument 2: cannot convert from 'method group' to 'EventCallback': Demo works.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found