How to get list of all invalid/unmapped columns in automapper using c# with .net core 2.2?

43 Views Asked by At

I am using automapper to map two models. In my case I am importing XML file and binding it to model using automapper. I want to show error message to the user which will have all invalid columns/mappings so that user can change it in XML file and upload again.

try
  {
      GradeImportDto gradeImportDto = JsonConvert.DeserializeObject<GradeImportDto>(exportXMLjson);
      RequestImportGradeDto requestGradeDto = Mapper.Map<RequestImportGradeDto>(gradeImportDto);
      Grade grade = Mapper.Map<Grade>(requestGradeDto);
   }                                                           
   catch (AutoMapperMappingException ex)
   {
      throw new ApplicationValidationException(AppConstants.INVALID_VALUES_EXEPTION, ex.InnerException);
   }

I am catching AutoMapperMappingException and can see destination member list there in inner exception also I can see unmapped members list(invalid mappings list) in messages part of inner exception but I am not sure how can I fetch that list.

Can any one help me in getting the list of unmapped members or invalid members.

0

There are 0 best solutions below