Skip to content

Fields mapped from .IncludeBase() not recognized during configuration validation #129

Description

Describe the bug
When migrating from AutoMapper, .IncludeBase() works as intended during mapping but no during validation: fields mapped from the base class are considered unmapped even though they are correctly handled when mapping child objects.

To Reproduce

// Minimal code to reproduce the issue
    private class TheBase { public string TheName { get; set; } }
    private class BaseDto { public string Name { get; set; } }

    private class Child : TheBase { public int MyProperty { get; set; } }
    private class ChildDto : BaseDto { public int MyProperty { get; set; } }

    var config = new MapperConfiguration(cfg =>
    {
        cfg.CreateMap<TheBase, BaseDto>().ForMember(dto => dto.Name, map => map.MapFrom(src => src.TheName));
        cfg.CreateMap<Child, ChildDto>().IncludeBase<TheBase, BaseDto>();
    });
    config.AssertConfigurationIsValid();  // <-- this throws

    var mapper = config.CreateMapper();
    var result = mapper.Map<ChildDto>(new Child { TheName = "aaa" });
    Assert.Equal("aaa", result.Name);  // <-- but this works

Expected behavior
Configuration is valid.

Actual behavior
Configuration is invalid, it throws the following exception:

System.InvalidOperationException : EggMapper configuration is invalid:
Unmapped destination member 'ChildDto.Name' in map Child -> ChildDto

Environment

  • EggMapper version: 1.17.18
  • .NET version: 10
  • OS: Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions