Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Error mapping types #1697


User avatar
0
amirventer created

Hi,

After upgrading ABP to version 0.12.0 I get an exception:

Error mapping types.

Mapping types: OutgoingTransaction -> OutgoingTransactionDto MyTestProject.Transactions.OutgoingTransaction -> MyTestProject.OutgoingTransactions.Dto.OutgoingTransactionDto

Type Map configuration: OutgoingTransaction -> OutgoingTransactionDto MyTestProject.Transactions.OutgoingTransaction -> MyTestProject.OutgoingTransactions.Dto.OutgoingTransactionDto

Property: TruckHaulierName

I have the following models that I've stripped down:

[Table("twtcOutgoingTransactions")]
    public class OutgoingTransaction : FullAuditedEntity
    {
        public DateTime TransactionDate { get; set; }
        public int TruckId { get; set; }
        public virtual Truck Truck { get; set; }
        public OutgoingTransaction()
        {
            TransactionDate = DateTime.Now;
        }
    }

[Table("twtcTrucks")]
    public class Truck : FullAuditedEntity, IPassivable
    {
        public string RegistrationNumber { get; set; }
        public int HaulierId { get; set; }
        [ForeignKey("HaulierId")]
        public virtual Haulier Haulier { get; set; }

        public bool IsActive { get; set; }

        public Truck()
        {
            IsActive = true;
        }
    }

[Table("twtcHauliers")]
    public class Haulier : FullAuditedEntity, IPassivable
    {
        //Code
        public string Name { get; set; }
        public string Description { get; set; }
        public bool IsInternal { get; set; }
        public bool IsActive { get; set; }

        public Haulier()
        {
            IsActive = true;
        }
    }

Here is my dto:

[AutoMap(typeof(OutgoingTransaction))]
    public class OutgoingTransactionDto : EntityDto
    {
        public DateTime TransactionDate { get; set; }
        public int TruckHaulierId { get; set; }
        public int TruckId { get; set; }
        public string TruckHaulierName { get; set; }
        public string TruckRegistrationNumber { get; set; }

        public OutgoingTransactionDto()
        {
            TransactionDate = DateTime.Now;
        }
    }

And here is my application service method that I've also stripped down (Error on - var dto = transaction.MapTo<OutgoingTransactionDto>();):

public OutgoingTransactionDto GetTransactionForEdit(int? id)
        {
            //var transaction = !id.HasValue ? new OutgoingTransaction() : _outgoingTransactionRepository.Get(id.Value);
            var transaction = new OutgoingTransaction();


            //transaction.Truck = new Truck {RegistrationNumber = "Blah"/*, Haulier = new Haulier {Name = "Cool"}*/ };

            var dto = transaction.MapTo<OutgoingTransactionDto>();  //error on this line

            return dto;
        }

I've also created an empty console application with just auto mapper and it works:

class Program
    {
        static void Main(string[] args)
        {
            Mapper.Initialize(cfg => cfg.CreateMap<OutgoingTransaction, OutgoingTransactionDto>());


            var transaction = new OutgoingTransaction();

            var dto = Mapper.Map<OutgoingTransaction>(transaction);

        }
    }

What am I missing?

Any help would be appreciated. :-)

Regards, Amir Venter


3 Answer(s)
  • User Avatar
    0
    amirventer created

    Okay my initial console code was incorrect, it should be :

    class Program
        {
            static void Main(string[] args)
            {
                Mapper.Initialize(cfg => cfg.CreateMap<OutgoingTransaction, OutgoingTransactionDto>());
    
    
                var transaction = new OutgoingTransaction();
    
                var dto = Mapper.Map<OutgoingTransactionDto>(transaction);
    
            }
        }
    

    Using automapper 5.1.1 it gives me the error but if I use version 5.0.2 or less then it works...

    So the issue is automapper

  • User Avatar
    0
    amirventer created

    I've created an issue over at AutoMapper.

    [https://github.com/AutoMapper/AutoMapper/issues/1683])

  • User Avatar
    0
    hikalkan created
    Support Team

    Thank you for informing us. Yes, it seems not related to ABP.