Skip to content

Throw for invalid string values of unsigned enums in JSON - #39068

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/json-enum-reader-invalid-string
Sep 22, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/json-enum-reader-invalid-string

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

JsonWarningEnumReaderWriter inverted the ulong.TryParse check for enums with an unsigned underlying type, so a string that is neither a member name nor a number was silently materialized as the default value instead of throwing BadEnumValue like it does for signed enums.

  • [x ] I've read the guidelines for contributing and seen the walkthrough
  • [x ] I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • [x ] The code builds and tests pass locally (also verified by our automated build checks)
  • [x ] Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • [x ] Tests for the changes have been added (for bug fixes / features)
  • [x ] Code follows the same patterns and style as existing code in this repo

JsonWarningEnumReaderWriter inverted the ulong.TryParse check for enums
with an unsigned underlying type, so a string that is neither a member
name nor a number was silently materialized as the default value
instead of throwing BadEnumValue like it does for signed enums.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@ilkertskn
ilkertskn requested a review from a team as a code owner September 22, 2026 21:04
@AndriySvyryd
AndriySvyryd requested a lite review from Copilot September 22, 2026 21:57

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit d32d70b into dotnet:main Sep 22, 2026
20 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The change and regression coverage address the invalid unsigned-enum behavior with no unresolved blocking issues.

Review effort: Lite
Findings: None

What changed in this PR

This pull request fixes invalid unsigned enum string values in JSON parsing so they throw BadEnumValue instead of becoming the default value.

Changes:

  • Corrects the ulong.TryParse condition.
  • Adds regression coverage for valid and invalid enum strings.
File Description
test/​EFCore.Tests/​Storage/​Json/​JsonWarningEnumReaderWriterTest.cs Adds regression tests for enum parsing.
src/​EFCore/​Storage/​Json/​JsonWarningEnumReaderWriter.cs Fixes unsigned enum parsing fallback behavior.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants