EGG1004 — Unmapped destination member
| Property | Value |
|---|---|
| Severity | Warning |
| Package | EggMapper.Analyzers |
| Category | EggMapper |
Description
A destination member of a CreateMap<TSource, TDestination>() has no source member: no source property with the same name (case-insensitive), no flattened path such as Customer.Name for CustomerName, and no ForMember that maps or ignores it. AssertConfigurationIsValid() would report the same member at run time; EGG1004 reports it while you build, with the fix in the message.
AutoMapper, Mapster and AgileMapper report these members only at run time, in configuration validation or on the first map. With EGG1004 an unfinished map shows up in dotnet build and in the IDE, which is where AI coding assistants and people notice it first.
Example (triggers warning)
public class Order { public string CustmerName { get; set; } public decimal Subtotal { get; set; } }
public class OrderDto { public string CustomerName { get; set; } public decimal Total { get; set; } }
public class OrderProfile : Profile
{
public OrderProfile() => CreateMap<Order, OrderDto>();
}
warning EGG1004: Destination member 'OrderDto.CustomerName' has no source member in CreateMap<Order, OrderDto>().
Fix: .ForMember(d => d.CustomerName, o => o.MapFrom(s => s.CustmerName)) or .ForMember(d => d.CustomerName, o => o.Ignore()).
warning EGG1004: Destination member 'OrderDto.Total' has no source member in CreateMap<Order, OrderDto>().
Configure: .ForMember(d => d.Total, o => o.MapFrom(s => ...)) or .ForMember(d => d.Total, o => o.Ignore()).
A Fix: is given only for a confident match (a one-letter typo of a same-type member, singular/plural, or a single nested member with the same name). Otherwise the closest source members are listed as Options:.
How to fix
Paste the Fix: line onto the CreateMap chain, map the member with ForMember(d => d.X, o => o.MapFrom(s => ...)), ignore it with o.Ignore(), or add a matching source property.
When EGG1004 stays silent
EGG1004 only reports what it can prove from the code, so it stays silent when a map is configured in ways it cannot read:
- the map is stored in a variable or passed to another method before it is configured;
- the chain calls
ConvertUsing,ConvertUsingEnumMapping,ForAllMembers,ForAllOtherMembers,IncludeBaseor your own extension method; - a
ForMemberoptions argument is not an inline lambda; - the project sets
ShouldMapPropertyor usesIncludeAllDerivedanywhere; - the reverse direction of
ReverseMap()(keep the validation test for it).
Keep one test that calls config.CompileMappings() and config.AssertConfigurationIsValid(): it covers every case.
How to change the severity
In .editorconfig, make unmapped members fail the build, or turn the check off:
dotnet_diagnostic.EGG1004.severity = error
dotnet_diagnostic.EGG1004.severity = none