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
{{ message }}
Repository navigation
Registration order causes ResolutionContext.OverTypeDepth to access Context.Items in AutoMapper 16.2.0 #4657
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:
dotnet 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.
Activity
Add regression test for registration-order MaxDepth context failure (#…