Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.2K
Vistas
Blazor Wasm - cannot convert from 'method group' to 'EventCallback'

I have a simple Blazor Server app that works ok.

I'm trying to create an equivalent app using Blazor WebAssembly with dotnet 5.

In the working app, I have a razor component that enables the user to upload files using the BlazorFileUploader nuget package

Markup:

<InputFile multiple OnChange="HandleFileSelected"/>

Code behind:

public async Task HandleFileSelected(IFileListEntry[] files)
        {
            if (!ValidateFiles(files, out _errorMsg))
            {
                return;
            }
etc...

When I try to compile the wasm app, I get the following error

CS1503 Argument 2: cannot convert from 'method group' to 'EventCallback'

error image

Any ideas what I'm doing wrong?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

I dont think the OnChange eventcallback supports a parameter of type IFileListEntry[]

Try to change your code behind to:

public async Task HandleFileSelected(InputFileChangeEventArgs e)
{
    var files = e.GetMultipleFiles();
}
over 4 years ago · Santiago Trujillo Denunciar

0

Jonas is correct; your method needs to accept InputFileChangeEventArgs instead of IFileListEntry[]. If you hover over OnChange in Visual Studio 2019, you should see something like this: enter image description here

The event handler expects a delegate EventCallback that can accept up to 1 parameter of type InputFileChangeEventArgs. Think of a delegate as a method interface: your declaration of IFileListEntry[] does not match the interface, so you are getting an error.

If you inspect InputFileChangeEventArgs, you can see how to get the files:

public async Task HandleFileSelected(InputFileChangeEventArgs args)
{
    IReadOnlyList<Microsoft.AspNetCore.Components.Forms.IBrowserFile> files =
        args.GetMultipleFiles(args.FileCount);
    // ...
over 4 years ago · Santiago Trujillo Denunciar

0

Thanks to Connor and Jonas for the answers. The cause of the problem was that the old Blazor Server app from was built using .Net Core 3.1. This does not contain a "InputFile" component in the Microsoft.AspNetCore.Components.Forms Namespace. This explains why I'd resorted to the 3rd party "BlazorFileUploader" nuget package.

When building the new Blazor WebAssembly app, I'd chosen dotnet 5. The problem was, the markup was now resolving "InputFile" to the Microsoft.AspNetCore.Components.Forms Namespace rather than the BlazorFileUploader namespace.

So, I could fix in one of two ways:

  • Fully qualify the markup to <BlazorFileUploader.InputFile
  • Remove the 3rd party nuget package and refactor the code to make use of the InputFile component now available in the dotnet5 version of the Microsoft namespace

I decided to go with the seconds of the two options.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda