Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

654
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!