Skip to content

Registration order causes ResolutionContext.OverTypeDepth to access Context.Items in AutoMapper 16.2.0 #4657

Description

@rdeeptools

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:

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.

Example

AutoMapper16RecursiveGraphInvestigation.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions