Issue with automapper in dotnet core webapi argument exception
Poimen opened this issue · 1 comments
Poimen commented
Hi,
Our project is using the start guide and mostly works as advertised. However, once we add automapper into the mix, we're facing an exception failure:
System.ArgumentException: GenericArguments[0], 'System.Int64', on 'T MaxFloat[T](System.Collections.Generic.IEnumerable`1[T])' violates the constraint of type 'T'.
The simple version of the models and config:
public class C1 : IRequest<long>
{
public string FirstName { get; set; }
}
public class C2
{
public string FirstName { get; set; }
}
var mapperConfig = new MapperConfiguration(cfg => {
cfg.CreateMap<C1, C2>();
});
IMapper mapper = mapperConfig.CreateMapper();
services.AddSingleton(mapper);
The system throws the exception on cfg.CreateMap<C1, C2>();
If I remove IRequest<long>
from the C1
model, all works as expected.
I can't work out why automapper does not like the IRequest
interface. As far as I can tell, the IRequest
is just a marker.
Have you ever seen this before?
Poimen commented
The typical one-last-search, and found the issue:
AutoMapper/AutoMapper#3988
Upgraded to v12, and fixed the issue.
Thanks 👍