You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Put your source/destination types here//SourcepublicclassResultSet{publicstring[,] IDMap {get;set;}}//DestpublicclassDTO{publicstring[,] IDMap {get;set;}}
Mapping configuration
// Mapper.Initialize or just the CreateMap snippet varconfig=new MapperConfiguration(c =>{ c.CreateMap<ResultSet,DTO>().ReverseMap();});
Version: x.y.z
4.2.1
Expected behavior
A null result would map to an empty 2d array of string[,]
Actual behavior
The null mapped to an empty 1d array of string[] then threw an inner System.InvalidCastException trying to map from string[] to string[,]
Steps to reproduce
Create two classes with one of the fields being a multidimensional array. Set the value of that multidimensional array in the instance of the source class to null, then attempt to map it to the destination class.
// Your calls to Mapper.Map or ProjectTo here, with source/destination objects constructedvarsource=new ResultSet {IDMap=null};try{vardest= mapper.Map<DTO>(source);}catch(Exceptionex){
ex.ToString();}
Stacktrace:
AutoMapper.AutoMapperMappingException:
Mapping types:
String[,] -> String[,]
System.String[,] -> System.String[,]
Destination path:
ResultSet.IDMap.IDMap
Source value:
(null) ---> System.InvalidCastException: Unable to cast object of type 'System.String[]' to type 'System.String[,]'.
at lambda_method(Closure , Object , Object )
at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.AssignValue(PropertyMap propertyMap, Object mappedObject, Object propertyValueToAssign)
at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, Object mappedObject, PropertyMap propertyMap)
--- End of inner exception stack trace ---
The text was updated successfully, but these errors were encountered:
burns140
changed the title
A null value for a multi-dimensional array results in an empty one-dimensional array, resulting in an InvalidCastException.
A null value for a multi-dimensional array results in an empty one-dimensional array, throwing an InvalidCastException.
Mar 4, 2021
lbargaoanu
changed the title
A null value for a multi-dimensional array results in an empty one-dimensional array, throwing an InvalidCastException.
InvalidCastException with multi-dimensional arrays
Mar 5, 2021
gist: https://gist.github.com/burns140/53b8c0c571534b7af0192ee329ecec60
Source/destination types
Mapping configuration
Version: x.y.z
4.2.1
Expected behavior
A null result would map to an empty 2d array of string[,]
Actual behavior
The null mapped to an empty 1d array of string[] then threw an inner System.InvalidCastException trying to map from string[] to string[,]
Steps to reproduce
Create two classes with one of the fields being a multidimensional array. Set the value of that multidimensional array in the instance of the source class to null, then attempt to map it to the destination class.
Stacktrace:
The text was updated successfully, but these errors were encountered: