C# 错误CS0121:编译时自动映射出现问题

C# 错误CS0121:编译时自动映射出现问题,c#,.net,automapper,C#,.net,Automapper,所以mapper在我的项目中不起作用 services.AddAutoMapper(); 错误: Startup.cs(112,21):错误CS0121:以下方法或属性之间的调用不明确:“ServiceCollectionExtensions.AddAutoMapper(IServiceCollection,params Assembly[])和“ServiceCollectionExtensions.AddAutoMapper(IServiceCollection,params Type[]

所以mapper在我的项目中不起作用

services.AddAutoMapper();
错误:

Startup.cs(112,21):错误CS0121:以下方法或属性之间的调用不明确:“ServiceCollectionExtensions.AddAutoMapper(IServiceCollection,params Assembly[])和“ServiceCollectionExtensions.AddAutoMapper(IServiceCollection,params Type[])”[/Users/admin/Desktop/YP/youplay/server/youplay.Api/youplay.csproj]

当我改为:

services.AddAutoMapper(typeof(Startup));
它是编译的,但是,当我试图使req

    public async Task<ActionResult<BetOpenForm>> CreateBetAsync([FromBody]CreateBetForm bet)
    {
        BetOpenForm response;
        try
        {

            BetOpen newBet = await _betService.CreateBetOpenAsync(bet);
           response = _mapper.Map<BetOpenForm>(newBet);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex.Message);
           // return new BadRequestObjectResult(new ApiError("Something gone wrong ;("));
             return new BadRequestObjectResult(new ApiError(ex.Message));
        }

        return Ok(response);
    }
公共异步任务

型号:

using System;
using System.Collections.Generic;

namespace YouPlay.Api.Controllers.ViewModels.Bet
{
    public class BetOpenForm
    {
        public string Id { get; set; }
        public int StreamId { get; set; }
        public List<BetOptionForm> BetOptions { get; set; }
        public string Title { get; set; }
        public string Author { get; set; }
        public string AuthorId { get; set; }
    }
}


using System;

namespace YouPlay.Api.Controllers.ViewModels.Bet
{
    public class BetOptionForm
    {
        public string Id { get; set; }
        public string BetOpenId { get; set; }
        public string OptionText { get; set; }
        public double Odd { get; set; }
        public decimal Amount { get; set; }
        public int BetsCount { get; set; }
    }
}
使用系统;
使用System.Collections.Generic;
命名空间YouPlay.Api.Controllers.ViewModels.Bet
{
公共类BetOpenForm
{
公共字符串Id{get;set;}
public int StreamId{get;set;}
公共列表选项{get;set;}
公共字符串标题{get;set;}
公共字符串作者{get;set;}
公共字符串AuthorId{get;set;}
}
}
使用制度;
命名空间YouPlay.Api.Controllers.ViewModels.Bet
{
公共类BetOptionForm
{
公共字符串Id{get;set;}
公共字符串BetOpenId{get;set;}
公共字符串OptionText{get;set;}
公共双奇数{get;set;}
公共十进制数{get;set;}
公共整数计数{get;set;}
}
}

当然,我有很多控制器,当我使用services.AddAutoMapper(typeof(Startup))时,它们会注入automapper,这不是错误,但后来mapper就不起作用了。