0

I have used Automapper 2.2.1.0 in my C# project and sometimes in production server, it's giving Error.

Type: AutoMapperMappingException Message:
Mapping types: IDataReader -> List`1 System.Data.IDataReader -> System.Collections.Generic.List`1 [[Repository.AgriAdvisor, Repository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]

Below is my code

Sqlhelper _helper = new Sqlhelper(ObjConnection);
List<T> varObj = null;
try
{
    var sqlrdr = _helper.GetReaderByCmdWithParameter(spName, parameters);
    using (_helper)
    {
        if (sqlrdr.HasRows)
        {
            Mapper.Initialize(cfg => cfg.CreateMap<IDataReader, List<T>>());
            varObj = Mapper.DynamicMap<IDataReader, List<T>>(sqlrdr);
        }
    }
    return varObj;
}
catch (Exception ex)
{
    throw ex;
}

kindly help me why this error is coming and it's not coming always sometimes it's gives error and maximum number of times it's working fine.

Yurii
  • 4,811
  • 7
  • 32
  • 41
ABD
  • 1
  • Unrelated to the question, but best practice nevertheless - you're [loosing the stacktrace](https://stackoverflow.com/a/178464/2974754) of your exception, use `throw;` instead. – Yurii May 03 '18 at 10:55
  • AutoMapper is not a full-featured ORM. It does have `AutoMapper.Data` for mapping data readers, but personally I'd still go with Dapper instead, which is explicitly designed as an ORM. – Jeroen Mostert May 03 '18 at 11:00
  • Thank you everyone ...actually, the project is in live stage and I cannot change the DLL files nor the architecture of it. Is there anything else that I can do? – ABD May 03 '18 at 13:16

0 Answers0