C# InvalidOperationException: Unable to resolve service for type 'AutoMapper.Mapper'

报错信息:

InvalidOperationException: Unable to resolve service for type 'AutoMapper.Mapper'

while attempting to activate 'BLL.Implementation.Report'.

检查后发现名称写错了

错误:

private readonly Mapper _mapper;

正确的是:

private readonly IMapper _mapper;

另外一种情况是没有在startup类的ConfigureServices中注入automapper依赖

先在Nuget里下载AutoMapper 之后再startup文件引用,最后注入依赖

原文地址:https://www.cnblogs.com/lixia0604/p/14009564.html