@@ -254,7 +254,14 @@ private void AddPathMaps(List<Expression> actions)
254254 continue ;
255255 }
256256
257- actions . Add ( TryPathMap ( pathMap ) ) ;
257+ try
258+ {
259+ actions . Add ( TryPathMap ( pathMap ) ) ;
260+ }
261+ catch ( Exception e ) when ( e is not AutoMapperConfigurationException )
262+ {
263+ throw new AutoMapperMappingException ( "Error building path mapping strategy." , e , pathMap ) ;
264+ }
258265 }
259266 }
260267
@@ -287,14 +294,21 @@ private void AddPropertyMaps(List<Expression> actions)
287294 continue ;
288295 }
289296
290- var property = TryMemberMap ( propertyMap ,
291- CreatePropertyMapFunc ( propertyMap , _destination , propertyMap . DestinationMember ) ) ;
292- if ( _typeMap . ConstructorParameterMatches ( propertyMap . DestinationName ) )
297+ try
293298 {
294- property = _initialDestination . IfNullElse ( _configuration . Default ( property . Type ) , property ) ;
299+ var property = TryMemberMap ( propertyMap ,
300+ CreatePropertyMapFunc ( propertyMap , _destination , propertyMap . DestinationMember ) ) ;
301+ if ( _typeMap . ConstructorParameterMatches ( propertyMap . DestinationName ) )
302+ {
303+ property = _initialDestination . IfNullElse ( _configuration . Default ( property . Type ) , property ) ;
304+ }
305+
306+ actions . Add ( property ) ;
307+ }
308+ catch ( Exception e ) when ( e is not AutoMapperConfigurationException )
309+ {
310+ throw new AutoMapperMappingException ( "Error building member mapping strategy." , e , propertyMap ) ;
295311 }
296-
297- actions . Add ( property ) ;
298312 }
299313 }
300314
@@ -366,9 +380,16 @@ private Expression ConstructorMapping(ConstructorMap constructorMap)
366380 List < Expression > body = [ ] ;
367381 foreach ( var parameter in constructorMap . CtorParams )
368382 {
369- var variable = Variable ( parameter . DestinationType , parameter . DestinationName ) ;
370- variables . Add ( variable ) ;
371- body . Add ( Assign ( variable , CreateConstructorParameterExpression ( parameter ) ) ) ;
383+ try
384+ {
385+ var variable = Variable ( parameter . DestinationType , parameter . DestinationName ) ;
386+ variables . Add ( variable ) ;
387+ body . Add ( Assign ( variable , CreateConstructorParameterExpression ( parameter ) ) ) ;
388+ }
389+ catch ( Exception e ) when ( e is not AutoMapperConfigurationException )
390+ {
391+ throw new AutoMapperMappingException ( "Error building constructor parameter mapping strategy." , e , parameter ) ;
392+ }
372393 }
373394
374395 body . Add ( CheckReferencesCache ( New ( constructorMap . Ctor , variables ) ) ) ;
0 commit comments