AutoMapperAnalyzer.Analyzers 1.5.805.1834

dotnet add package AutoMapperAnalyzer.Analyzers --version 1.5.805.1834
                    
NuGet\Install-Package AutoMapperAnalyzer.Analyzers -Version 1.5.805.1834
                    
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="1.5.805.1834">
  <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="1.5.805.1834" />
                    
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 1.5.805.1834
                    
#r "nuget: AutoMapperAnalyzer.Analyzers, 1.5.805.1834"
                    
#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@1.5.805.1834
                    
#: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=1.5.805.1834
                    
Install as a Cake Addin
#tool nuget:?package=AutoMapperAnalyzer.Analyzers&version=1.5.805.1834
                    
Install as a Cake Tool

๐ŸŽฏ AutoMapper Roslyn Analyzer

Build Status NuGet Coverage License: MIT

โœจ Catch AutoMapper configuration errors before they cause runtime chaos
A sophisticated Roslyn analyzer that transforms AutoMapper development from reactive debugging to proactive prevention


๐ŸŒŸ Why This Matters

AutoMapper is powerful, but silent failures are its Achilles' heel. Properties that don't map, type mismatches that throw at runtime, nullable violations that cause NullReferenceExceptionsโ€”these issues typically surface in production, not during development.

This analyzer changes that equation entirely.

// Before: ๐Ÿ˜ฐ Runtime surprise!
public void MapUserData()
{
    var user = mapper.Map<UserDto>(userEntity); 
    // ๐Ÿ’ฅ NullReferenceException in production
    // ๐Ÿ’ฅ Data loss from unmapped properties  
    // ๐Ÿ’ฅ Type conversion failures
}

// After: ๐Ÿ›ก๏ธ Compile-time confidence!
public void MapUserData() 
{
    var user = mapper.Map<UserDto>(userEntity);
    // โœ… All mapping issues caught at compile-time
    // โœ… Code fixes suggest proper solutions
    // โœ… Ship with confidence
}

๐Ÿš€ What You Get

๐Ÿ›ก๏ธ Complete Type Safety

  • AM001: Property type mismatches with smart conversion suggestions
  • AM002: Nullable-to-non-nullable mapping with null safety patterns
  • AM003: Collection type incompatibility detection

๐Ÿ” Zero Data Loss

  • AM004: Missing destination properties (prevent silent data loss)
  • AM011: Required property validation (avoid runtime exceptions)
  • AM005: Case sensitivity issues (cross-platform reliability)

๐Ÿงฉ Complex Mapping Intelligence

  • AM020: Nested object mapping validation with CreateMap suggestions
  • AM021: Collection element type analysis with conversion strategies
  • AM022: Circular reference detection with MaxDepth recommendations
  • AM030: Custom type converter analysis with null safety validation

โšก Instant Code Fixes

Every analyzer comes with intelligent code fixes that don't just identify problemsโ€”they solve them:

// Problem detected โš ๏ธ
cfg.CreateMap<Source, Dest>();
//    ~~~~~~~~~~~~~~~~~~~~~~~~~ AM001: Property 'Age' type mismatch

// Code fix applied โœจ
cfg.CreateMap<Source, Dest>()
   .ForMember(dest => dest.Age, opt => opt.MapFrom(src => 
       int.TryParse(src.Age, out var age) ? age : 0));

๐ŸŽฏ Real-World Impact

Before After
๐Ÿ› Runtime mapping failures โœ… Compile-time validation
๐Ÿ” Manual debugging sessions โœ… Instant error highlights
๐Ÿ“ Guessing correct configurations โœ… Code fixes with best practices
โš ๏ธ Production NullReferenceExceptions โœ… Null safety enforcement
๐Ÿ“Š Silent data loss โœ… Missing property detection
๐ŸŒ Cross-platform mapping inconsistencies โœ… Case sensitivity validation

๐Ÿ“ฆ Installation

Quick Start - Package Manager

Install-Package AutoMapperAnalyzer.Analyzers
Install-Package AutoMapperAnalyzer.CodeFixes  

.NET CLI

dotnet add package AutoMapperAnalyzer.Analyzers
dotnet add package AutoMapperAnalyzer.CodeFixes
<PackageReference Include="AutoMapperAnalyzer.Analyzers" Version="1.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="AutoMapperAnalyzer.CodeFixes" Version="1.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

โšก Universal Compatibility

Platform Version Support AutoMapper CI/CD Status
.NET Framework 4.8+ ๐ŸŸข Full 10.1.1+ โœ… Tested
.NET 6.0+ ๐ŸŸข Full 12.0.1+ โœ… Tested
.NET 8.0+ ๐ŸŸข Full 14.0.0+ โœ… Tested
.NET 9.0+ ๐ŸŸข Full 14.0.0+ โœ… Tested

Analyzer targets .NET Standard 2.0 for maximum compatibility
All platforms validated in automated CI/CD pipeline


๐ŸŽจ See It In Action

โŒ The Problems

public class UserEntity
{
    public int Id { get; set; }
    public string? FirstName { get; set; }  // Nullable
    public string LastName { get; set; }
    public string Email { get; set; }
    public DateTime CreatedAt { get; set; }
    public List<string> Tags { get; set; }  // Collection type
    public Address HomeAddress { get; set; }  // Complex object
}

public class UserDto  
{
    public int Id { get; set; }
    public string FirstName { get; set; }    // Non-nullable!
    public string FullName { get; set; }     // Different property!  
    public string Age { get; set; }          // Different type!
    public HashSet<int> Tags { get; set; }   // Incompatible collection!
    public AddressDto HomeAddress { get; set; }  // Needs explicit mapping!
}

// This configuration has MULTIPLE issues:
cfg.CreateMap<UserEntity, UserDto>();
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  ๐Ÿšจ AM002: FirstName nullableโ†’non-nullable (NullReferenceException risk)
//  ๐Ÿšจ AM004: LastName will not be mapped (data loss)  
//  ๐Ÿšจ AM001: Age expects int but gets DateTime (runtime exception)
//  ๐Ÿšจ AM021: Tags List<string>โ†’HashSet<int> incompatible (mapping failure)
//  ๐Ÿšจ AM020: HomeAddressโ†’AddressDto needs CreateMap (runtime exception)
//  ๐Ÿšจ AM030: Custom converter missing ConvertUsing configuration

โœ… The Solutions (Auto-Generated!)

// Code fixes automatically suggest:
cfg.CreateMap<UserEntity, UserDto>()
   .ForMember(dest => dest.FirstName, opt => opt.MapFrom(src => src.FirstName ?? ""))
   .ForMember(dest => dest.FullName, opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"))  
   .ForMember(dest => dest.Age, opt => opt.MapFrom(src => 
       DateTime.Now.Year - src.CreatedAt.Year))
   .ForMember(dest => dest.Tags, opt => opt.MapFrom(src => 
       src.Tags.Select((tag, index) => index).ToHashSet()));

// Separate mapping for complex types  
cfg.CreateMap<Address, AddressDto>();

โš™๏ธ Fine-Tuned Control

Severity Configuration (.editorconfig)

# Treat type safety as build errors
dotnet_diagnostic.AM001.severity = error
dotnet_diagnostic.AM002.severity = error  
dotnet_diagnostic.AM011.severity = error

# Data loss warnings  
dotnet_diagnostic.AM004.severity = warning
dotnet_diagnostic.AM005.severity = warning

# Suggestions for optimization
dotnet_diagnostic.AM020.severity = suggestion
dotnet_diagnostic.AM021.severity = suggestion  

Selective Suppression

// Suppress with clear justification
#pragma warning disable AM001 // Custom IValueConverter handles stringโ†’int
cfg.CreateMap<Source, Dest>();
#pragma warning restore AM001

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

๐Ÿ“Š Complete Analyzer Coverage

Rule Description Analyzer Code Fix Severity
๐Ÿ”’ Type Safety
AM001 Property Type Mismatch โœ… โœ… Warning
AM002 Nullableโ†’Non-nullable โœ… โœ… Warning
AM003 Collection Incompatibility โœ… โœ… Warning
๐Ÿ“Š Data Integrity
AM004 Missing Destination Property โœ… โœ… Info
AM005 Case Sensitivity Issues โœ… โœ… Info
AM011 Required Property Missing โœ… โœ… Error
๐Ÿงฉ Complex Mappings
AM020 Nested Object Issues โœ… โœ… Warning
AM021 Collection Element Mismatch โœ… โœ… Warning
AM022 Circular Reference Risk โœ… โœ… Warning
AM030 Custom Type Converter Issues โœ… โœ… Warning
๐Ÿš€ Future
AM031+ Performance Analysis ๐Ÿ”ฎ ๐Ÿ”ฎ -
AM040+ Configuration Rules ๐Ÿ”ฎ ๐Ÿ”ฎ -
AM050+ Advanced Optimizations ๐Ÿ”ฎ ๐Ÿ”ฎ -

๐Ÿ› ๏ธ Development Experience

IDE Integration

  • Visual Studio: Full IntelliSense integration with lightbulb code fixes
  • VS Code: Rich diagnostic experience via OmniSharp
  • JetBrains Rider: Native analyzer support with quick-fix suggestions
  • Command Line: Works seamlessly with dotnet build

Testing Your Configuration

# Quick validation
dotnet build  # Analyzer runs automatically

# Comprehensive testing
git clone https://github.com/georgepwall1991/automapper-analyser.git
cd automapper-analyser
dotnet run --project samples/AutoMapperAnalyzer.Samples

# See all analyzer warnings in action
dotnet build samples/ --verbosity normal

# Run full test suite with coverage
dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettings

CI/CD & Quality Assurance

  • ๐Ÿ”„ Automated Testing: Every commit tested across multiple .NET versions
  • ๐Ÿ“Š Code Coverage: Integrated with Codecov for comprehensive coverage tracking
  • ๐Ÿ›ก๏ธ Quality Gates: Build fails only on genuine errors, warnings are preserved
  • โšก Cross-Platform: Validated on Ubuntu (CI) and Windows (compatibility tests)
  • ๐Ÿ“ˆ Performance: Incremental builds with analyzer caching for optimal speed

๐Ÿ—๏ธ Architecture Highlights

This isn't just another analyzerโ€”it's built for enterprise-grade reliability:

  • ๐ŸŽ๏ธ Performance-First: Incremental analysis with minimal IDE impact
  • ๐Ÿ”ง Extensible Design: Clean plugin architecture for new rules
  • ๐Ÿงช Battle-Tested: 130+ unit tests covering edge cases (100% passing)
  • ๐ŸŒ Cross-Platform: Identical behavior on Windows, macOS, Linux
  • โšก CI/CD Ready: Automated GitHub Actions with codecov integration
  • ๐Ÿ“Š Code Coverage: 55%+ coverage with comprehensive testing

๐ŸŽฏ What's Next

Phase 5B: Enhanced Analysis (In Progress)

  • AM030: Custom type converter validation โœ… COMPLETE
  • AM031: Performance warning analysis with optimization suggestions
  • AM040: Profile registration analysis and auto-registration fixes
  • AM041: Conflicting mapping rule detection and resolution

Beyond Code Analysis

  • NuGet Package Templates: Project templates with pre-configured analyzers
  • MSBuild Integration: Custom build targets for mapping validation
  • Documentation Generation: Auto-generate mapping documentation
  • Metrics Dashboard: Build-time analysis reporting

๐Ÿค Contributing

We're building something special, and your expertise makes it better.

Quick Start Contributing:

git clone https://github.com/georgepwall1991/automapper-analyser.git
cd automapper-analyser
dotnet test  # All 130+ tests should pass

What We Need:

  • ๐Ÿงช More edge-case scenarios
  • ๐Ÿ“ Documentation improvements
  • ๐Ÿš€ Performance optimizations
  • ๐Ÿ’ก New analyzer rule ideas

See our Contributing Guide for detailed guidelines.


๐Ÿ“š Deep Dive Resources


๐Ÿ’ฌ Community & Support

Get Help:

  • ๐Ÿ› Issues - Bug reports and feature requests
  • ๐Ÿ’ฌ Discussions - Questions and ideas
  • ๐Ÿ“– Wiki - Comprehensive documentation

๐Ÿ“„ License

MIT License - Use it anywhere, contribute back if you can.


<div align="center">

โญ Star this repo if it's saving you time!

Built with โค๏ธ by developers who've debugged too many AutoMapper issues

๐Ÿš€ Get Started Now โ€ข ๐Ÿ“– Read the Docs โ€ข ๐Ÿ’ฌ Join the Discussion

</div>

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
1.5.805.1834 15 8/5/2025
1.5.805.1514 12 8/5/2025
1.5.724.2155 439 7/24/2025
1.5.722.1040 478 7/22/2025
1.5.722.25 474 7/21/2025
1.5.611.1239 289 6/11/2025
1.5.611.1228 277 6/11/2025
1.5.611.1119 281 6/11/2025
1.5.606.1627 92 6/6/2025
1.5.606.1343 99 6/6/2025
1.5.606.1341 96 6/6/2025
1.5.606.1035 110 6/6/2025
1.5.606.946 118 6/6/2025
1.5.606.940 107 6/6/2025
1.0.4 109 6/6/2025
1.0.3 140 6/5/2025
1.0.2 141 6/5/2025
1.0.1 135 6/5/2025
1.0.0 137 6/5/2025

Fixed: Code fix providers are now properly included in the NuGet package. The analyzer now provides automatic fixes for detected issues including type mismatches, missing properties, and configuration problems.