"The best compatible overloaded method has some invalid arguments"

Asked

Viewed 884 times

1

I’m creating a service with a method that has an argument like List<OrdemPais>(), and passing an object of this type to the method, but when compiling it appears the error:

O melhor método sobrecarregado compatível com 'Mahikari.Business.Domain.OrdemPaisVigencia.SetOrdensPaises(System.Collections.Generic.List<Mahikari.Business.Domain.OrdemPais>)' tem alguns argumentos inválidos

This is the part of the code that the method is called:

protected void salvar_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
            return;

        SalvarEstadoOrdem();

        List<OrdemPais> OrdemPaisList = new List<OrdemPais>();


        OrdemPaisVigencia.Vigencia = dteVigencia.SelectedDate.Value;

        List<OrdemPais> ordemPaises = new List<OrdemPais>();
        foreach (KeyValuePair<int, int> ordem in ordens)
        {
            var o = new OrdemPais(ordem.Key, ordem.Value);
            ordemPaises.Add(o);
        }

        try
        {
            OrdemPaisVigencia.SetOrdensPaises(ordemPaises);

            paisService.SaveOrdemPais(OrdemPaisVigencia);
        }
        catch (Exception ex)
        {

        }

        Response.Redirect("OrdemPais.aspx", true);
    }

The method itself:

public void SetOrdensPaises(List<OrdemPais> ordemPaises)
    {
        if (ordemPaises.Any())
            this.Validation.Errors.Add(MainResource.Mensagem_ListaNaoPodeEstarVazia);

        this.OrdemPaises = ordemPaises.OrderBy(or => or.Ordem).ToList();
    }
  • The error is in the build or execution?

  • Compilation, and the strange thing is that it doesn’t signal with the red underscore (which usually stays in the visual studio when it’s wrong).

  • I can not identify any problem seeing only this. It may be missing something. But this code has several strange things. I don’t know if the problem may be being caused by something else. If you can make a [mcve] it may be easier to help.

  • I’m going to put the whole method of that code snippet, which has weird @bigown ?

  • It’s strange because both the call and the signature apparently has the same type. Certifies that the OrdemPais in List<OrdemPais> ordemPaises = new List<OrdemPais>(); is exactly the same in SetOrdensPaises(List<OrdemPais> ordemPaises). I mean, if they are not being referenced from separate Dlls despite having the same name.

  • 1

    @Ericwu was exactly that, the class (which is in another DLL) had the same name as a page, so it gave the error. If you want you can answer the question so I can mark it as an answer!

Show 1 more comment

1 answer

1


Make sure that the OrdemPais in

List<OrdemPais> ordemPaises = new List<OrdemPais>(); 

is exactly the same OrdemPais in

SetOrdensPaises(List<OrdemPais> ordemPaises);

If they have the same name but are in different namespaces, they are essentially different types.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.