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.

@jbogard jbogard merged commit d9c1fbb into main Feb 21, 2026
10 checks passed
@jbogard jbogard deleted the 4597-mapatruntime-with-with-non-nullable-to-nullable-mapping-fails-when-extension-methods-are-used branch February 21, 2026 17:08
This was referenced Mar 4, 2026
PhilipWoulfe pushed a commit to PhilipWoulfe/F1Competition that referenced this pull request Mar 10, 2026
Updated [AutoMapper](https://github.com/LuckyPennySoftware/AutoMapper)
from 14.0.0 to 16.1.0.

<details>
<summary>Release notes</summary>

_Sourced from [AutoMapper's
releases](https://github.com/LuckyPennySoftware/AutoMapper/releases)._

## 16.1.0

## What's Changed
* Add Debug and Release build configurations to slnx by @​Copilot in
LuckyPennySoftware/AutoMapper#4590
* Migrating to slnx by @​jbogard in
LuckyPennySoftware/AutoMapper#4589
* Allow disabling of polymorphic LINQ mapping by @​jbogard in
LuckyPennySoftware/AutoMapper#4596
* Fix duplicate BOM in ServiceCollectionExtensions.cs by @​Copilot in
LuckyPennySoftware/AutoMapper#4600
* Fix review feedback: double semicolon, DI condition integration test,
docs example by @​Copilot in
LuckyPennySoftware/AutoMapper#4601
* Adding DI-enabled conditions and pre-conditions; updated docs accordi…
by @​jbogard in
LuckyPennySoftware/AutoMapper#4599
* Adding support for DI-enabled destination factories. by @​jbogard in
LuckyPennySoftware/AutoMapper#4603
* Correctly converting nullables for MapAtRuntime; fixes #​4597 by
@​jbogard in LuckyPennySoftware/AutoMapper#4604
* Correctly handling consecutive uppercase characters; fixes #​4593 by
@​jbogard in LuckyPennySoftware/AutoMapper#4605
* Wrapping the exception to provide better feedback to the user; fixes …
by @​jbogard in
LuckyPennySoftware/AutoMapper#4606
* Fixing bug around order of open generic registration by @​jbogard in
LuckyPennySoftware/AutoMapper#4607
* Adding perpetual licensing by @​jbogard in
LuckyPennySoftware/AutoMapper#4608

## New Contributors
* @​Copilot made their first contribution in
LuckyPennySoftware/AutoMapper#4590

**Full Changelog**:
LuckyPennySoftware/AutoMapper@v16.0.0...v16.1.0

## 16.0.0

## What's Changed
* Fix release pipelines by @​jbogard in
LuckyPennySoftware/AutoMapper#4583
* Adding support for .NET 10 by @​jbogard in
LuckyPennySoftware/AutoMapper#4586


**Full Changelog**:
LuckyPennySoftware/AutoMapper@v15.1.0...v16.0.0

## 16.0.0-beta-1

## What's Changed
* Fix release pipelines by @​jbogard in
LuckyPennySoftware/AutoMapper#4583
* Adding support for .NET 10 by @​jbogard in
LuckyPennySoftware/AutoMapper#4586

**Full Changelog**:
LuckyPennySoftware/AutoMapper@v15.1.0...v16.0.0-beta-1

This release is a beta release that introduces .NET 10 support and
package signing. Signed packages means going forward packages can be
validated against trusted authorities that the package has been
published by Lucky Penny Software and not tampered with.

## 15.1.0

## What's Changed
* remove Microsoft.SourceLink.GitHub by @​SimonCropp in
LuckyPennySoftware/AutoMapper#4555
* Direct .NET 4.x support by @​jbogard in
LuckyPennySoftware/AutoMapper#4569
* Bumping the JsonWebTokens because of GHSA-8g4q-xg66-9fp4; fixes #​4575
by @​jbogard in
LuckyPennySoftware/AutoMapper#4576
* Provide better exceptions for errors when building the mapping plan by
@​jbogard in LuckyPennySoftware/AutoMapper#4577
* Adding docs for license configuration by @​jbogard in
LuckyPennySoftware/AutoMapper#4581
* Updating refs to fix missing method issue by @​jbogard in
LuckyPennySoftware/AutoMapper#4582

## New Contributors
* @​SimonCropp made their first contribution in
LuckyPennySoftware/AutoMapper#4555

**Full Changelog**:
LuckyPennySoftware/AutoMapper@v15.0.1...v15.1.0

## 15.0.1

## What's Changed
* Removing public signing; fixes #​4545 by @​jbogard in
LuckyPennySoftware/AutoMapper#4552
* Adding back missing overloads and reverting registering behavior by
@​jbogard in LuckyPennySoftware/AutoMapper#4554


**Full Changelog**:
LuckyPennySoftware/AutoMapper@v15.0.0...v15.0.1

This release supersedes the 15.0.0 release, reverting behavior and
overloads so that the `AddAutoMapper` overloads separate the "scanning
for maps" from the "scanning for dependencies". Unfortunately it's not
really possible to combine these two together.

This also fixes a critical bug in #​4545 that does not work with .NET
4.x applications (as intended).

Because of this, the 15.0.0 will be delisted because of the breaking
changes there.

## 15.0.0

**Full Changelog**:
LuckyPennySoftware/AutoMapper@v14.0.0...v15.0.0

* Added support for .NET Standard 2.0
* Requiring license key
* Moving from MIT license to dual commercial/OSS license

To set your license key:

```csharp
services.AddAutoMapper(cfg => {
    cfg.LicenseKey = "<License key here>";
});
```

This also introduced a breaking change with `MapperConfiguration`
requiring an `ILoggerFactory` for logging purposes:

```csharp
public MapperConfiguration(MapperConfigurationExpression configurationExpression, ILoggerFactory loggerFactory)
```

Registering AutoMapper with `services.AddAutoMapper` will automatically
supply this parameter. Otherwise you'll need to supply the logger
factory.

You can obtain your license key at
[AutoMapper.io](https://automapper.io)

Commits viewable in [compare
view](LuckyPennySoftware/AutoMapper@v14.0.0...v16.1.0).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=AutoMapper&package-manager=nuget&previous-version=14.0.0&new-version=16.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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