没有为此对象,automapper 8和IValueResolver定义无参数的构造函数

时间:2019-02-14 00:33:47

标签: c# dependency-injection automapper-8

我在项目中使用AutoMapper 8,并且想使用解析器,如下所示。我收到此消息错误的问题:

  

MissingMethodException:没有为此定义无参数构造函数   对象。

我不知道我是否想念这里的东西。

public class ExcelClientProfile : Profile
    {
        public ExcelClientProfile()
        {
            CreateMap<Ticket, ExcelClient>()
                ...
                .ForMember(d => d.FormModel, s => s.MapFrom<FormBuilderWithAnswerResolver>());
        }
    }

    public class FormBuilderWithAnswerResolver : IValueResolver<Ticket, ExcelClient, FormModel>
    {
        private IFormBuilderService _formBuilderService;

        public FormBuilderWithAnswerResolver(IFormBuilderService formBuilderService)
        {
            _formBuilderService = formBuilderService;
        }

        public FormModel Resolve(Ticket source, ExcelClient destination, FormModel destMember, ResolutionContext context)
        {
            return _formBuilderService.GetFormBuilderWithAnswersExcel(source);
        }
    }

你知道我该怎么做吗?

谢谢

大卫


Stacktrace

  

处理请求时发生未处理的异常。   MissingMethodException:没有为此定义无参数构造函数   宾语。 System.RuntimeTypeHandle.CreateInstance(RuntimeType类型,布尔   publicOnly,bool wrapExceptions,引用bool canBeCached,ref   RuntimeMethodHandleInternal ctor)

     

AutoMapperMappingException:错误映射类型。

     

映射类型:票证-> ExcelClient Core.Models.Ticket->   Service.Models.TicketOrderView.ExcelClient

     

类型映射配置:票证-> ExcelClient Core.Models.Ticket->   Service.Models.TicketOrderView.ExcelClient

     

目标成员:FormModel lambda_method(Closure,   IQueryable,ICollection,ResolutionContext)

     

AutoMapperMappingException:错误映射类型。

     

映射类型:IQueryable 1 -> ICollection 1   System.Linq.IQueryable 1[[Core.Models.Ticket, Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.ICollection 1 [[Service.Models.TicketOrderView.ExcelClient,   服务,版本= 1.0.0.0,文化=中性,公钥令牌=空]]

还有:

    public class Ticket : Entity
        {
            public int Id { get; set; }
            ...
            public virtual FormBuilder FormBuilder { get; set; }
            public Ticket()
            {

            }

            public object Clone()
            {
                return this.MemberwiseClone();
            }
        }

        public class ExcelClient
        {
            ...
public virtual FormModel FormModel { get; set; }
            public ExcelClient()
            {

            }
        }

0 个答案:

没有答案