-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[release/7.0] Prefer TypeConverter over TryParse #46687
Conversation
Hi @github-actions[bot]. If this is not a tell-mode PR, please make sure to follow the instructions laid out in the servicing process document. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was curious about this when we were looking at individual DateOnly and TimeOnly model binders. I'll leave the official approving review to someone more knowledgeable, but this fix looks great to me
Yeah, when we added the |
Hi @github-actions[bot]. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Hi @github-actions[bot]. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed. |
Approved via email. @dotnet/aspnet-build Can I get help merging? |
Backport of #46577 to release/7.0
/cc @brunolins16
Prefer TypeConverter over TryParse
This PR reverts a break change introduced in .NET 7 where the
MVC Model Binding
prefers aTryParse
method over aTypeConverter
for asimple type
.Fixes #46384
Fixes #45338
Customer Impact
In .NET 7 was added a new Model Binder to enable binding from a string using a known
TryParse
method, in addition to aTypeConverter
, however, was decided to register the new Model Binder to be executed first (preferringTryParse
overTypeConverter
) while all the functionality still in place and users still able to use aTypeConverter
there are situations where a type already have aTryParse
method and aTypeConverter
and they have different default options (#45338), or when a user is trying to create a customTypeConverter
to these types (#46384).This PR keeps the new Model Binder, however, will maintain compatibly with .NET 6 by preferring
TypeConverter
over aTryParse
method.Regression?
The regression was introduced in .NET when the new
TryParseModelBinder
was added.Risk
All the new functionality added in .NET 7 (Bind with
TryParse
) will keep working, however, we are making it more compatible with what we have before.Verification
Packaging changes reviewed?