[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. |
Nick-Stanton
left a comment
There was a problem hiding this comment.
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 Bindingprefers aTryParsemethod over aTypeConverterfor 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
TryParsemethod, in addition to aTypeConverter, however, was decided to register the new Model Binder to be executed first (preferringTryParseoverTypeConverter) while all the functionality still in place and users still able to use aTypeConverterthere are situations where a type already have aTryParsemethod and aTypeConverterand they have different default options (#45338), or when a user is trying to create a customTypeConverterto these types (#46384).This PR keeps the new Model Binder, however, will maintain compatibly with .NET 6 by preferring
TypeConverterover aTryParsemethod.Regression?
The regression was introduced in .NET when the new
TryParseModelBinderwas 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?