Automapper not finding type map configuration for child property

391 Views Asked by At

I'm using AutoMapper 6.1.1.0 and have the following types:

Source:

public class PaymentPlan
{
    private List<ScheduledPayment> _scheduledPayments = new List<ScheduledPayment>();
    private Rates _ratesApplied;

    public Rates RatesApplied
    {
        get { return _ratesApplied; }
        set { _ratesApplied = value; }
    }

    public List<ScheduledPayment> ScheduledPayments
    {
        get { return _scheduledPayments; }
        set { _scheduledPayments = value; }
    }
}

Dest:

public class PaymentPlanModel
{
    public RatesModel RatesApplied { get; set; }

    public List<ScheduledPaymentModel> ScheduledPayments { get; set; }
}

public class ClassEnrollmentPaymentPlanVM : PaymentPlanModel
{
    public Guid PricePlanID { get; set; }

    public string Name { get; set; }

    public bool IsSelected { get; set; }

    public bool AutoDraftEnabled { get; set; }

    public bool BillingDayChoiceEnabled { get; set; }

    public List<int> AvailableBillingDays { get; set; }

    public int SelectedBillingDay { get; set; }
}

Mapping config profile:

CreateMap<Rates, RatesModel>();
CreateMap<ScheduledPayment, ScheduledPaymentModel>();
CreateMap<PaymentPlan, PaymentPlanModel>();
CreateMap<PaymentPlan, ClassEnrollmentPaymentPlanVM>();
    //.IncludeBase<PaymentPlan, PaymentPlanModel>();

ClassEnrollmentPaymentPlanVM inherits PaymentPlanModel. I'm trying to map from a source PaymentPlan into a ClassEnrollmentPaymentPlanVM to populate all the base PaymentPlanModel properties, but it's complaining that it is "Missing type map configuration or unsupported mapping." for Rates -> RatesModel. In troubleshooting this error I tried commenting out my IncludeBase call but get the same result. I have quadruple checked the namespaces are correct. Why isn't it finding my mapping from Rates to RatesModel?

Edit:

The mapping is initiated like this:

private static IMapper _mapper = MapperConfig.EntityWebMapper;
...

PaymentPlan paymentPlan = pmtCalc.CalculatePaymentPlan(calcInput);

ClassEnrollmentPaymentPlanVM paymentPlanVM = _mapper.Map<ClassEnrollmentPaymentPlanVM>(paymentPlan);

And the exact exception/error message is an AutoMapperMappingException stating:

Error mapping types.

Mapping types: PaymentPlan -> ClassEnrollmentPaymentPlanVM CRM.Logic.CRM.PaymentCalculation.PaymentPlan -> CRM.MVCWeb.ViewModels.Enrollment.ClassEnrollmentPaymentPlanVM

Type Map configuration: PaymentPlan -> ClassEnrollmentPaymentPlanVM CRM.Logic.CRM.PaymentCalculation.PaymentPlan -> CRM.MVCWeb.ViewModels.Enrollment.ClassEnrollmentPaymentPlanVM

Property: RatesApplied

Inner Exception Message:

Missing type map configuration or unsupported mapping.

Mapping types: Rates -> RatesModel CRM.Logic.CRM.PaymentCalculation.Rates -> CRM.MVCWeb.Models.PaymentCalculation.RatesModel

0

There are 0 best solutions below