Repository navigation
Catch exception in TryConvertTo #33594
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
Closed
+120
−0
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
85e753d
Add test for TryConvertTo for GUID type
jeffl8n a6e00f6
Catch exception in TryConvertTo
jeffl8n db06351
Change to Guid specific Converter
jeffl8n a574ba1
Add case for Nullable Guid
jeffl8n a698a17
Merge branch 'main' into issue-33587
jeffl8n ca8ea8f
Add tests for NullableGuid
jeffl8n 91224f1
Fix NullableGuid parse reflect a null as parsed
jeffl8n ecb43b2
Merge branch 'main' into issue-33587
jeffl8n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
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 must be missing something here. How come you don't need a
try/catchany more? I thought that adding thetry/catchwas the main reason for the change.Does structuring the code this way somehow mean there isn't an unhandled exception any more? If you could clarify that would be great!
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.
Yes, because before the
GuidConverterwould call the ctor which throws on invalid values. #33587 (comment)You can see it in the stack trace from here #33587 (comment)
Should there be another case for
Guid??Uh oh!
There was an error while loading. Please reload this page.
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.
That's correct. Calling Guid.TryParse sets the ThrowStyle to None - https://github.com/dotnet/runtime/blob/5221db92ed579f8ffa56f1d8e84f07ba6d896077/src/libraries/System.Private.CoreLib/src/System/Guid.cs#L242
But calling the Guid ctor sets the ThrowStyle to All - https://github.com/dotnet/runtime/blob/5221db92ed579f8ffa56f1d8e84f07ba6d896077/src/libraries/System.Private.CoreLib/src/System/Guid.cs#L210
Do you mean like the check for null/empty string? The Guid class performs several checks for length and formatting, so that current check could be removed as well, but I left it since it would prevent having to call TryParse for the simplest invalid case.
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 meant for the
typeof(Guid?)type, all the others do both checks liketypeof(DateTimeOffset)andtypeof(DateTimeOffset?):aspnetcore/src/Components/Components/src/BindConverter.cs
Lines 1495 to 1502 in a6e00f6
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.
You're right. I've just added another case for Nullable Guid.