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

255
Visualizações
The call is ambiguous between IDictionary<string, object> and IDictionary

I am using a Library with a class that have the following constructors:

public JobDataMap(IDictionary<string, object> map);

public JobDataMap(IDictionary map);

I created an instance of JobDataMap:

var jdm = new JobDataMap(new Dictionary<String, Object> { 
  { "Manager", myObject } 
});

But I am getting the compilation error:

The call is ambiguous between the following methods or properties:
'JobDataMap.JobDataMap(IDictionary<string, object>)' and 'JobDataMap.JobDataMap(IDictionary)' 

How to solve this?

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

0

You can cast it to the type for the constructor you want it to use:

var jdm = new JobDataMap((IDictionary<string, object>) new Dictionary<String, Object> {
    { "Manager", new object() }
});

This design does seem a bit dubious, however...

over 4 years ago · Santiago Trujillo Relatório

0

You can enforce the type being passed like so:

var jdm = new JobDataMap((IDictionary<string, object>)new Dictionary<String, Object> { 
  { "Manager", myObject } 
});

Or you could make a factory method and make the non-generic constructor (I'm assuming you use this less) private:

public class JobDataMap
{
    public JobDataMap(IDictionary<string, object> map)
    {
    }

    private JobDataMap(IDictionary map)
    {
    }

    public static JobDataMap FromNonGenericMap(IDictionary map)
    {
        return new JobDataMap(map);
    }
}

Usage:

var jdm = JobDataMap.FromNonGenericMap(someNonGenericDictionary);

and then you can use the regular generic one like so:

var jdm = new JobDataMap(new Dictionary<String, Object> { 
  { "Manager", myObject } 
});
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