Fix: MapAtRuntime exception with nullable target types and extension methods (AutoMapper #4597 backport)#10
Closed
gthen95 wants to merge 1 commit intoNET-Sorcery:mainfrom
Closed
Conversation
… methods (fixes #4597)
Collaborator
|
Thank you for your initiative. Unfortunately I cannot accept your contributions, since they are seems to be just rehashed work of @jbogard which is bad sport. I understand that this is trivial change, but when compounded it can be legal issue. As you may notice this repository still have MIT license, but original AutoMapper is not. You may try to go to authors of PR's and ask them to confirm that their change is under MIT. anyway you should keep authorship intact. If you want attribution, I think that can be handled with Co-authored or something similar. Anyway PR probably would count as such. |
Contributor
Author
|
Ok, I understand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR backports a fix from AutoMapper (#4597) to resolve a runtime exception when combining
.MapAtRuntime()with extension methods targeting a nullable type.The Issue:
When using
.MapAtRuntime()alongside.MapFrom(src => src.Value.ExtensionMethod())where the destination type is nullable (e.g.,int?), the mapping throws a runtime exception. The expression builder passes the source parameter directly without explicitly converting it to the expected type of the generic expression.The Fix:
Added an explicit
ToType()(orExpression.Convert) cast to the source parameter insideContextMapbefore passing it to theExpression.Call. This ensures type safety and prevents the runtime crash.References: