The following mapping code causes automapper to throw an exception when the map is done.
mapper.CreateMap<SqlDataReader, CodeModel>()
.ForMember(dest => dest.Code,
options => options.MapFrom(src => src["code"] != null ?
src["code"].ToString() :
string.Empty));
This is really bizarre, src["code"] has a value, it is "E", this is even stated in the automapper message.
Does anyone have any insight into what this issue or how to solve this issue?
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] AutoMapper.Mappers.TypeMapMapper.Map(ResolutionContext context, IMappingEngineRunner mapper) +116
AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context) +459[AutoMapperMappingException:
Mapping types: String -> String System.String -> System.String
Destination path: CodeModel.Code
Source value: E]
AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context) +537
AutoMapper.Mappers.DataReaderMapper.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap) +305
AutoMapper.Mappers.DataReaderMapper.MapPropertyValues(ResolutionContext context, IMappingEngineRunner mapper, Object result) +210
AutoMapper.Mappers.DataReaderMapper.Map(ResolutionContext context, IMappingEngineRunner mapper) +639
AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context) +477 AutoMapper.MappingEngine.Map(Object source, Type sourceType, Type destinationType, Action1 opts) +1761 opts) +162
AutoMapper.MappingEngine.Map(Object source, Action
AutoMapper.MappingEngine.Map(Object source) +143