Skip to content

Correctly converting nullables for MapAtRuntime; fixes #4597#4604

Merged
jbogard merged 1 commit intomainfrom
4597-mapatruntime-with-with-non-nullable-to-nullable-mapping-fails-when-extension-methods-are-used
Feb 21, 2026
Merged

Correctly converting nullables for MapAtRuntime; fixes #4597#4604
jbogard merged 1 commit intomainfrom
4597-mapatruntime-with-with-non-nullable-to-nullable-mapping-fails-when-extension-methods-are-used

Conversation

@jbogard
Copy link
Contributor

@jbogard jbogard commented Feb 21, 2026

No description provided.

Copy link
Contributor

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 fixes issue #4597 by correctly converting nullable types when using MapAtRuntime(). The issue occurred when mapping from a non-nullable value type (e.g., int from an extension method result) to a nullable destination property (e.g., int?) with MapAtRuntime enabled.

Changes:

  • Added type conversion in ContextMap to ensure source expressions match the expected generic type parameter
  • Added comprehensive test coverage for the nullable conversion scenario with extension methods

Reviewed changes

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

File Description
src/AutoMapper/Execution/ExpressionBuilder.cs Adds ToType conversion to ensure source parameter type matches typePair.SourceType before calling MapInternal
src/UnitTests/Bug/MapAtRuntime/MapAtRuntimeWithExtensionMethodAndNullable.cs Adds test class with two test methods covering both non-null and null source scenarios when mapping extension method results to nullable destinations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MapAtRuntime with with non-nullable to nullable mapping fails when extension methods are used

2 participants