AutoMapperAnalyzer.Analyzers 2.30.89

There is a newer version of this package available.
See the version list below for details.
dotnet add package AutoMapperAnalyzer.Analyzers --version 2.30.89
                    
NuGet\Install-Package AutoMapperAnalyzer.Analyzers -Version 2.30.89
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoMapperAnalyzer.Analyzers" Version="2.30.89">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AutoMapperAnalyzer.Analyzers" Version="2.30.89" />
                    
Directory.Packages.props
<PackageReference Include="AutoMapperAnalyzer.Analyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AutoMapperAnalyzer.Analyzers --version 2.30.89
                    
#r "nuget: AutoMapperAnalyzer.Analyzers, 2.30.89"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AutoMapperAnalyzer.Analyzers@2.30.89
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AutoMapperAnalyzer.Analyzers&version=2.30.89
                    
Install as a Cake Addin
#tool nuget:?package=AutoMapperAnalyzer.Analyzers&version=2.30.89
                    
Install as a Cake Tool

AutoMapper Roslyn Analyzer

Compile-time AutoMapper CreateMap validation for .NET — a high-signal Roslyn analyzer that checks Profile, CreateMap, ForMember, MapFrom, ReverseMap, ConvertUsing, and ProjectTo configurations so type mismatches, nullable holes, unmapped required members, and missing registrations fail in the editor and CI, not as AutoMapperMappingException in production.

NuGet Version NuGet Downloads Build Status Tests .NET Compatibility License Coverage

Catch AutoMapper configuration errors at compile-time before they cause runtime chaos.

The problem

AutoMapper is powerful, but many mapping failures compile cleanly. A property type mismatch on CreateMap, a nullable source into a non-nullable destination, an unmapped required member, a nested object without its own map, or a Map/ProjectTo call with no reachable registration typically surfaces as a runtime exception, silent default, or production NullReferenceException — not as a compile error.

Runtime tests and manual review miss what static analysis can prove from your mapping configuration.

What it catches

AutoMapperAnalyzer reports high-signal mapping problems early:

  • property type mismatches on CreateMap (AM001) with conversion or Ignore code fixes
  • nullable → non-nullable mappings that risk null failures (AM002)
  • incompatible collection containers and element types (AM003 / AM021)
  • missing source members, unmapped destinations, case-only name drift, and required members (AM004 / AM005 / AM006 / AM011)
  • nested object maps that need an extra CreateMap (AM020)
  • circular reference risk without MaxDepth / PreserveReferences (AM022)
  • invalid, null-unsafe, or unused type converters (AM030 / AM032 / AM033)
  • expensive or multi-enumeration mapping expressions (AM031 / AM034–AM038)
  • duplicate registrations, redundant MapFrom, and unregistered Map/ProjectTo pairs (AM041 / AM050 / AM060)
  • enum member name/value misalignment that silently corrupts mapped data (AM061)

When the analyzer cannot prove a mapping shape statically, it stays quiet. High-signal feedback, not noisy guesses. Code fixes are withheld when a rewrite would be side-effecting, incomplete, or behavior-changing without review.

Install

<PackageReference Include="AutoMapperAnalyzer.Analyzers" Version="2.30.89">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

Or:

dotnet add package AutoMapperAnalyzer.Analyzers --version 2.30.89

No runtime dependency is added to your app. The package is a development-time Roslyn analyzer (plus code fixes). Open any file with AutoMapper configuration and diagnostics appear in supported IDEs and dotnet build.

See the compatibility contract for verified target-framework and AutoMapper version pairings.

See it work

Product-flow diagrams from real sample diagnostics (tests/.../sample-diagnostics.json):

1. Build / IDE diagnostics (CreateMap validation)

AutoMapper Roslyn analyzer warnings for CreateMap validation — AM001 type mismatch, AM002 nullable, AM011 required property, AM060 unregistered Map/ProjectTo

2. Before / after code fix (property type mismatch)

Before and after: AutoMapper CreateMap string-to-int Age mismatch fixed with ForMember MapFrom TryParse (AM001)

3. IDE + CI product loop

AutoMapper analyzer product loop: IDE lightbulb diagnostics and CI package/sample compatibility gates for CreateMap Profiles

30-second path

  1. Reference the package with PrivateAssets="all".
  2. Keep your existing profiles, for example:
public class UserProfile : Profile
{
    public UserProfile()
    {
        CreateMap<User, UserDto>();
    }
}
  1. Build in the IDE or with ContinuousIntegrationBuild=true on the command line so analyzers run under this repo’s local defaults.
  2. Fix any AMxxx diagnostics (most rules offer code fixes; review scaffold / likely-rewrite actions).
  3. Optionally open the samples project to see the full rule set in one place:
dotnet build samples/AutoMapperAnalyzer.Samples

Feature snapshot

Area What the analyzer does
Type safety Flags property type mismatches, nullable polarity, and collection container incompatibility.
Data integrity Detects missing source members, unmapped destinations, case-only drift, and required members.
Nested / graph maps Requires nested CreateMap pairs, analyzes collection elements, and warns on recursion risk.
Converters Validates ITypeConverter / IValueConverter implementation, null handling, and usage.
Performance Flags multi-enumeration, expensive work, sync-over-async, heavy LINQ, and non-determinism in maps.
Configuration Finds duplicate CreateMap, redundant MapFrom, and Map/ProjectTo without a reachable registration.
Code fixes Offers conversion, Ignore, nested-map, and scaffolding actions when a rewrite is safe enough to propose.
Honesty Stays quiet when configuration is unprovable; withholds fixes that would drop sibling options or side effects.

Compatibility

Platform Version AutoMapper (verified)
.NET Framework 4.8+ 10.1.1+
.NET 6.0+ 12.0.1+
.NET 8.0+ / 9.0+ / 10.0+ 14.0.0+

Analyzer targets .NET Standard 2.0. Matrix details: docs/COMPATIBILITY.md.


Latest Release: v2.30.89

AutoMapper 15 and 16 verified in the compatibility contract

  • The published package is now built, installed, and diagnostic-verified against AutoMapper 14, 15 (15.1.3), and 16 (16.2.0) before every NuGet push, alongside the existing net48-am10 and net6-am12 cases. The matrix previously stopped at AutoMapper 14 while the current release is 16.2.0.
  • AutoMapper 15 introduced commercial licensing (cfg.LicenseKey). The compatibility consumers are compile-only, so this contract covers analyzer behaviour rather than runtime licensing — teams staying on AutoMapper 14 keep full coverage.
  • No analyzer rule ID, severity, or behaviour changes. For the previous release's IncludeMembers work see v2.30.88 in CHANGELOG.md.

Recent highlights

  • v2.30.89: AutoMapper 15 and 16 added to the verified compatibility contract.
  • v2.30.88: IncludeMembers awareness — AM004, AM006, and AM011 no longer report members supplied by an included source member.
  • v2.30.87: Discoverability assets (metadata, funnel README, product-flow SVGs, pack verify).
  • v2.30.86: AM020 capture-once computed receivers for nested-map fixes.
  • v2.30.85: AM021 withholds ineffective element-map fixes for nested collection/array shapes.
  • v2.30.84: AM060 unregistered Map/ProjectTo; AM061 enum member mismatch.
  • v2.30.62: Performance rules split into AM031 + AM034–AM038.

Full history: CHANGELOG.md.


Complete Analyzer Coverage

Rule Description Analyzer Code Fix Severity
Type Safety
AM001 Property Type Mismatch Error
AM002 Nullable→Non-nullable Error / Info
AM003 Collection Incompatibility Error
AM061 Enum Member Mismatch Warning
Data Integrity
AM004 Missing Destination Property Warning
AM005 Case Sensitivity Issues Warning
AM006 Unmapped Destination Property Info
AM011 Required Property Missing Error
Complex Mappings
AM020 Nested Object Issues Warning
AM021 Collection Element Mismatch Warning
AM022 Circular Reference Risk Warning
AM030 Invalid Type Converter Implementation Error
AM032 Type Converter Null Handling Warning
AM033 Unused Type Converter Info
Performance
AM031 Multiple Enumeration Warning
AM034 Expensive Operation Warning
AM035 Expensive Computation Warning
AM036 Sync-Over-Async Warning
AM037 Complex LINQ Warning
AM038 Non-Deterministic Operation Info
Configuration
AM041 Duplicate Mapping Registration Warning
AM050 Redundant MapFrom Info
AM060 Unregistered Type Map Warning

Example: one CreateMap, many issues

public class UserEntity
{
    public int Id { get; set; }
    public string? FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime CreatedAt { get; set; }
    public List<string> Tags { get; set; }
    public Address HomeAddress { get; set; }
}

public class UserDto
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string FullName { get; set; }
    public string Age { get; set; }
    public HashSet<int> Tags { get; set; }
    public AddressDto HomeAddress { get; set; }
}

cfg.CreateMap<UserEntity, UserDto>();
// AM002: FirstName nullable → non-nullable
// AM001 / related: type and shape mismatches on Age / Tags
// AM020: HomeAddress → AddressDto needs its own CreateMap
// AM006 / AM004 family: unmapped / missing members depending on direction

Code fixes can suggest ForMember conversions, Ignore, nested CreateMap, and aggregate map/ignore actions when safe enough to propose. Always review scaffold-level fixes.


Severity and suppression

.editorconfig

dotnet_diagnostic.AM001.severity = error
dotnet_diagnostic.AM002.severity = error
dotnet_diagnostic.AM011.severity = error

dotnet_diagnostic.AM004.severity = warning
dotnet_diagnostic.AM005.severity = warning

dotnet_diagnostic.AM020.severity = suggestion
dotnet_diagnostic.AM021.severity = suggestion

Selective suppression

#pragma warning disable AM001 // Custom IValueConverter handles string→int
cfg.CreateMap<Source, Dest>();
#pragma warning restore AM001

[SuppressMessage("AutoMapper", "AM004:Missing destination property",
    Justification = "PII data intentionally excluded for GDPR compliance")]
public void ConfigureSafeUserMapping() { }

Development experience

  • Visual Studio / Rider / VS Code (OmniSharp): diagnostics and lightbulb code fixes
  • CLI: dotnet build (this repo disables analyzers on local CLI builds unless ContinuousIntegrationBuild=true)
  • Samples: dotnet build samples/AutoMapperAnalyzer.Samples
  • Tests: dotnet test

CI / quality

  • Multi-TFM test suite and package compatibility matrix
  • Catalog, sample diagnostic snapshots, and package content verification
  • Codecov coverage reporting

Architecture notes

  • Incremental Roslyn analysis with minimal IDE impact
  • Central rule catalog for descriptors, fixers, samples, and fix-trust levels
  • Cross-platform behavior on Windows, macOS, and Linux
  • Conservative fix selection: no silent no-op lightbulbs; withhold when ownership cannot be proven

Contributing

git clone https://github.com/georgepwall1991/automapper-analyser.git
cd automapper-analyser
dotnet test

Useful contributions: edge-case scenarios, documentation, performance, and carefully scoped new rules.


Deep dive

Community

License

MIT — see LICENSE.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.30.107 0 7/31/2026
2.30.106 0 7/30/2026
2.30.105 0 7/30/2026
2.30.104 0 7/30/2026
2.30.103 22 7/30/2026
2.30.102 29 7/30/2026
2.30.101 37 7/30/2026
2.30.100 30 7/30/2026
2.30.99 30 7/30/2026
2.30.98 33 7/30/2026
2.30.97 79 7/29/2026
2.30.96 83 7/29/2026
2.30.95 76 7/29/2026
2.30.94 77 7/29/2026
2.30.93 73 7/29/2026
2.30.92 83 7/29/2026
2.30.91 85 7/28/2026
2.30.90 78 7/28/2026
2.30.89 77 7/28/2026
2.30.88 77 7/28/2026
Loading failed

Version 2.30.89 - AutoMapper 15 and 16 verified in the compatibility contract
- Package compatibility matrix extended with net10-am15 (15.1.3) and net10-am16 (16.2.0)
- Every published package is now built, installed, and diagnostic-verified against AutoMapper 14, 15, and 16 before release
- No analyzer rule ID, severity, or behaviour changes