Skip to content

Conversation

@jbogard
Copy link
Contributor

@jbogard jbogard commented Sep 5, 2025

This PR adds diagnostic exceptions around mapping individual members. If there's an exception building the expression trees there's not details given from those exceptions.

This covers:

  • In memory mapping strategies
    • The type map as a whole
    • Property maps
    • Path maps
    • Constructor maps
  • LINQ mapping
    • Property maps
    • Constructor maps

Fixes #4558, #4563

@jbogard jbogard linked an issue Sep 5, 2025 that may be closed by this pull request
@jbogard jbogard added this to the 15.1.0 milestone Sep 5, 2025
@jbogard jbogard requested a review from Copilot September 26, 2025 15:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds better error handling and diagnostic exceptions when building mapping strategies in AutoMapper. The change wraps critical mapping operations in try-catch blocks to provide more informative exceptions when expression tree building fails.

  • Wraps mapping operations in try-catch blocks to catch and re-throw as AutoMapperMappingException
  • Adds context-specific error messages for different mapping scenarios
  • Covers both in-memory mapping strategies and LINQ projection mapping

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/AutoMapper/TypeMap.cs Adds exception handling around type map sealing and expression creation
src/AutoMapper/QueryableExtensions/ProjectionBuilder.cs Adds exception handling for property projections and constructor parameter mapping in LINQ scenarios
src/AutoMapper/Execution/TypeMapPlanBuilder.cs Adds exception handling for path maps, property maps, and constructor parameter mapping in execution plans

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jbogard jbogard merged commit 6d3b6ae into master Oct 6, 2025
6 checks passed
@jbogard jbogard deleted the 4563-provide-better-diagnostic-exceptions-for-expression-tree-errors branch October 6, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide better diagnostic exceptions for expression tree errors Argument types do not match

1 participant