โจ Catch AutoMapper configuration errors before they cause runtime chaos
A sophisticated Roslyn analyzer that transforms AutoMapper development from reactive debugging to proactive prevention
Architecture Refactoring & Enhanced Bulk Fixes
๐๏ธ Architecture Improvements:
- Refactored Foundation: All 13 code fix providers now use new
AutoMapperCodeFixProviderBaseabstract class - Code Reduction: Eliminated ~500 lines of duplicated boilerplate code
- Standardization: Consistent error handling and node replacement patterns across all fixers
- Future-Ready: Improved maintainability and scalability for future enhancements
โจ New Features:
- Multi-Step Wizard: Interactive wizard for complex bulk fix scenarios
- Smart Chunking: Efficiently handles 30+ properties with intelligent chunking strategy
- Configuration Workflow: Comment-based workflow for complex mapping configurations
- Enhanced Batch Fixes: Improved batch fixing capabilities across all code fix providers
๐ง Quality:
- All 419 tests passing with 100% success rate
- Better UX for complex bulk fix scenarios
New Icon & Visual Update
- New Icon: Updated NuGet package icon to a modern, high-quality design
- Visual Identity: Improved branding for the analyzer package
Build & Stability Fixes
๐ ๏ธ Fixes:
- Fixed build errors in AM002 (Nullable Compatibility) and AM004 (Missing Destination Property) code fix providers
- Resolved issues with SyntaxEditor usage in newer Roslyn versions
- Improved stability of bulk code fixes
Bulk Code Fixes & Improved UX
โจ New Capabilities:
- ๐ฆ Bulk Code Fixes (AM011): Fix all unmapped required properties in one click!
- ๐๏ธ Action Grouping: Reduced lightbulb menu clutter by grouping property-specific fixes.
- ๐ง Smart Property Creation (AM004): Automatically detects missing destination properties and creates them in the destination class (even in separate files).
- ๐ Fuzzy Matching (AM011): Intelligent suggestions for unmapped required properties using Levenshtein distance matching (e.g., maps
UserNametoUsername). - ๐ ๏ธ Type Converter Generation (AM030): Instead of just a comment, generates a complete
IValueConverterclass implementation and wires it up. - โก Cross-File Performance Refactoring (AM031): Intelligently moves expensive computations from mapping profiles to source classes, handling cross-file modifications seamlessly.
- Smart Code Fixers: Advanced refactoring tools including fuzzy matching and property creation.
- Refactoring: Major improvements to code fix providers.
- ๐ .NET 10 Ready: Verified compatibility metadata for upcoming .NET 10.
- ๐งน Documentation Cleanup: Removed outdated reports and guides.
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
}# Install via .NET CLI
dotnet add package AutoMapperAnalyzer.Analyzers
# Or via Package Manager Console
Install-Package AutoMapperAnalyzer.AnalyzersThat's it! The analyzer automatically activates and starts checking your AutoMapper configurations. Open any file with AutoMapper mappings and see diagnostics appear instantly.
See it work:
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<User, UserDto>();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AM001: Property 'Age' type mismatch
// ๐ก Press Ctrl+. for code fix suggestions
});- AM001: Property type mismatches with smart conversion suggestions
- AM002: Nullable-to-non-nullable mapping with null safety patterns
- AM003: Collection type incompatibility detection
- AM004: Missing destination properties (prevent silent data loss)
- AM011: Required property validation (avoid runtime exceptions)
- AM005: Case sensitivity issues (cross-platform reliability)
- AM020: Nested object mapping validation with CreateMap suggestions (supports internal properties & cross-profile detection)
- AM021: Collection element type analysis with conversion strategies
- AM022: Circular reference detection with MaxDepth recommendations
- AM030: Custom type converter analysis with null safety validation
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));| 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 |
dotnet add package AutoMapperAnalyzer.AnalyzersInstall-Package AutoMapperAnalyzer.Analyzers<PackageReference Include="AutoMapperAnalyzer.Analyzers" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>| 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 |
| .NET | 10.0+ | ๐ข Full | 14.0.0+ | โ Tested |
Analyzer targets .NET Standard 2.0 for maximum compatibility
All platforms validated in automated CI/CD pipeline
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// 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>();# 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 // 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() { }| 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 |
| โก Performance | ||||
| AM031 | Performance Warnings | โ | โ | Warning |
| โ๏ธ Configuration | ||||
| AM041 | Duplicate Mapping Registration | โ | โ | Warning |
| AM050 | Redundant MapFrom | โ | โ | Info |
| ๐ Future | ||||
| AM032+ | Advanced Null Propagation | ๐ฎ | ๐ฎ | - |
| AM040+ | Configuration Rules | ๐ฎ | ๐ฎ | - |
| AM050+ | Advanced Optimizations | ๐ฎ | ๐ฎ | - |
- 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
# 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- ๐ 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
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: 418 unit tests with 405 passing, 13 skipped for known limitations (97% 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
- v2.5.0: Smart Code Fixers & Advanced Refactoring
- v2.4.1: .NET 10 Compatibility & Maintenance
- v2.4.0: Configuration & Redundancy Analysis (AM041, AM050)
- v2.3.2: ReverseMap support & Performance optimizations
- v2.2.0: AM031 Performance warning analyzer
- AM032: Advanced null propagation patterns with smart fixes
- AM040: Profile registration analysis and auto-registration fixes
- 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
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 testWhat We Need:
- ๐งช More edge-case scenarios
- ๐ Documentation improvements
- ๐ Performance optimizations
- ๐ก New analyzer rule ideas
See our Contributing Guide for detailed guidelines.
- ๐ Architecture Guide - How it all works under the hood
- ๐ Diagnostic Rules - Complete rule reference
- ๐งช Sample Gallery - Real-world scenarios
- ๐ CI/CD Pipeline - Our build and deployment process
- ๐ Compatibility Matrix - Framework support details
Get Help:
- ๐ Issues - Bug reports and feature requests
- ๐ฌ Discussions - Questions and ideas
- ๐ Wiki - Comprehensive documentation
MIT License - Use it anywhere, contribute back if you can.
Built with โค๏ธ by developers who've debugged too many AutoMapper issues
๐ Get Started Now โข ๐ Read the Docs โข ๐ฌ **Join the Discussion **