Versions
- AutoMapper 16.2.0
- .NET 10.0
- The issue was encountered while upgrading an application from AutoMapper 13.0.1 to 16.2.0.
Description
After upgrading from AutoMapper 13.0.1, mapping a recursive object graph with AutoMapper 16.2.0 started throwing an exception from ResolutionContext.OverTypeDepth.
The behavior depends only on type-map registration order. In the attached console application, registering the containing InitiativeEntity -> InitiativeModel map before EpicEntity -> EpicModel causes the failure. Swapping those two adjacent registrations makes the same mapping succeed.
The mapped source is an EpicEntity with populated Stories and WorkItems. The nested graph contains a WorkItemEntity -> EstimateEntity -> WorkItemEntity back-reference.
Reproduction
Run:
The application directly calls:
mapper.Map<EpicModel>(epic);
No mapping-operation options are used.
Actual behavior
AutoMapperMappingException: Error mapping types.
Destination Member: Stories
---> System.InvalidOperationException:
Context.Items are only available when using a Map overload that takes
Action<IMappingOperationOptions>! Consider using Context.TryGetItems instead.
at AutoMapper.ResolutionContext.OverTypeDepth(TypeMap typeMap)
Application code does not access Context.Items.
Expected behavior
Mapping should not depend on the order in which the two type maps are registered. The ordinary Map<TDestination>(source) overload should succeed without requiring mapping-operation options.
Workaround demonstrated by the reproduction
Register EpicEntity -> EpicModel before InitiativeEntity -> InitiativeModel.
Example
AutoMapper16RecursiveGraphInvestigation.zip
Versions
Description
After upgrading from AutoMapper 13.0.1, mapping a recursive object graph with AutoMapper 16.2.0 started throwing an exception from
ResolutionContext.OverTypeDepth.The behavior depends only on type-map registration order. In the attached console application, registering the containing
InitiativeEntity -> InitiativeModelmap beforeEpicEntity -> EpicModelcauses the failure. Swapping those two adjacent registrations makes the same mapping succeed.The mapped source is an
EpicEntitywith populatedStoriesandWorkItems. The nested graph contains aWorkItemEntity -> EstimateEntity -> WorkItemEntityback-reference.Reproduction
Run:
The application directly calls:
No mapping-operation options are used.
Actual behavior
Application code does not access
Context.Items.Expected behavior
Mapping should not depend on the order in which the two type maps are registered. The ordinary
Map<TDestination>(source)overload should succeed without requiring mapping-operation options.Workaround demonstrated by the reproduction
Register
EpicEntity -> EpicModelbeforeInitiativeEntity -> InitiativeModel.Example
AutoMapper16RecursiveGraphInvestigation.zip