Skip to content

Conversation

@brunolins16
Copy link
Member

@brunolins16 brunolins16 commented Feb 15, 2022

Fixes #39682

@Pilchie Pilchie added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Feb 15, 2022
@brunolins16 brunolins16 marked this pull request as ready for review February 17, 2022 22:27
@brunolins16 brunolins16 requested a review from javiercn February 17, 2022 22:28
@brunolins16 brunolins16 marked this pull request as draft February 17, 2022 22:32
@brunolins16 brunolins16 marked this pull request as ready for review February 18, 2022 16:16
Copy link
Contributor

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for driving this PR!

}
catch (InvalidOperationException)
{
// The ParameterBindingMethodCache.FindTryParseMethod throws an exception
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion - we could update FindTryParseMethod to not throw via an additional parameter. Not catching exceptions is certainly a lot nicer since it avoids things like first-chance exceptions in VS.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I will open a new PR just for that, ok?

Expression.Block(
Expression.Assign(modelValue, Expression.Convert(parsedValue, modelValue.Type)),
Expression.Assign(BindingResultExpression, Expression.Call(SuccessBindingResultMethod, modelValue))),
Expression.Call(AddModelErrorMethod, BindingContextExpression, Expression.Constant(new FormatException()))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is exactly what the TryAddModelError will do:

if (exception is FormatException || exception is OverflowException)

@brunolins16 brunolins16 enabled auto-merge (squash) March 3, 2022 18:24
@brunolins16 brunolins16 merged commit 3817558 into dotnet:main Mar 3, 2022
@ghost ghost added this to the 7.0-preview3 milestone Mar 3, 2022
@brunolins16 brunolins16 deleted the brunolins16/issues/39682 branch August 2, 2022 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider adding support for TryParse as a way to bind primitives

5 participants