EGG1002 — MapperConfiguration missing AssertConfigurationIsValid
| Property | Value |
|---|---|
| Severity | Warning |
| Package | EggMapper.Analyzers |
| Category | EggMapper |
Description
MapperConfiguration is constructed but AssertConfigurationIsValid() is never called anywhere in the compilation. Without this call, mapping mismatches (e.g., a destination property that has no source) are silent until the first Map<>() call at runtime.
Example (triggers warning)
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Order, OrderDto>();
});
// Missing: config.AssertConfigurationIsValid();
How to fix
Call AssertConfigurationIsValid() at application startup — before serving any requests:
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Order, OrderDto>();
});
config.AssertConfigurationIsValid(); // ← throws if any map is misconfigured
var mapper = config.CreateMapper();
The call can be in any method in the compilation — it does not need to be immediately after the constructor.
How to suppress
#pragma warning disable EGG1002
var config = new MapperConfiguration(...);
#pragma warning restore EGG1002
Or in .editorconfig:
dotnet_diagnostic.EGG1002.severity = none