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

655
Visualizações
Automapper throwing System.Reflection.AmbiguousMatchException: Ambiguous match found

I have a piece of code that throws exception and I dont quite understand why.

 public  async Task<List<CategoryVm>> Handle(GetCategoriesListQuery request, CancellationToken cancellationToken)
    {
        var categories = (await _categoryRepository.ListAllAsync()).OrderBy(x => x.Name);
      //  var list = categories.ToList();
        return _mapper.Map<List<CategoryVm>>(categories);
    }

enter image description here

I managed to get around problem as below. Would be be nice know why this works.

  public  async Task<List<CategoryVm>> Handle(GetCategoriesListQuery request, CancellationToken cancellationToken)
    {
        var categories = (await _categoryRepository.ListAllAsync()).OrderBy(x => x.Name);
        var list = categories.ToList();
        return _mapper.Map<List<CategoryVm>>(list);
    }

Category and CategoryVm

public class CategoryVm
{
    public Guid CategoryId { get; set; }
    public string Name { get; set; } 
}
public class Category: AuditableEntity
{
    public Guid CategoryId { get; set; }
    public string Name { get; set; }
    public ICollection<Event> Events { get; set; }
}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

In my case, the cause was using .OrderBy() method. My workaround was to use ordering afterwards mapping. If that's important, I'm using Automapper 11.0.0

over 4 years ago · Santiago Trujillo Relatório

0

In AutoMapper version 11.0.1 (now available) this bug is solved: calling IMapper.Map after an OrderBy caused an AmbiguousMatchException in version 11.0.0.

(A link to this GitHub issue was shared by @Lucian Bargaoanu in a comment already, while the issue was in progress. Thanks for sharing!)

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