Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.3K
Visualizações
Parameter count mismatch in property.GetValue()

I'm getting the

parameter count mismatch

error. It occurs at the if clause. My code:

private Dictionary<string,string> ObjectToDict(Dictionary<string, string> dict, object obj)
{
    var properties = obj.GetType().GetProperties();
    foreach (var property in properties)
    {
        if (property.GetValue(obj, null) != null)
            dict["{{" + property.Name + "}}"] = property.GetValue(obj, null).ToString();
    }
    return dict;
}

It's strange because it works just fine when I add the property value to the dictionary, but not when I'm testing if it's null in the if clause.

All the questions I've found were putting an incorrect number of arguments into the function call, but AFAIK there's nothing different between my two calls.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I'm pretty sure this is because your object type has an indexed property and you are passing null to the index parameter on the GetValue call.

Either remove the indexed property or filter out the indexed properties from your properties variable, for example:

var properties = obj.GetType().GetProperties()
                    .Where(p => p.GetIndexParameters().Length == 0);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda