Skip to content

Prevent InvalidCastException when attribute type does not match parameter type by adding safe type conversion.#66137

Open
minaxi98 wants to merge 2 commits intodotnet:mainfrom
minaxi98:fix/openapi-defaultparametervalue-cast/60019
Open

Prevent InvalidCastException when attribute type does not match parameter type by adding safe type conversion.#66137
minaxi98 wants to merge 2 commits intodotnet:mainfrom
minaxi98:fix/openapi-defaultparametervalue-cast/60019

Conversation

@minaxi98
Copy link
Copy Markdown

@minaxi98 minaxi98 commented Apr 4, 2026

Prevent InvalidCastException when attribute type does not match parameter type by adding safe type conversion.

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Description

The problem: when DefaultParameterValue(10) is used on a uint64 parameter, the 10 is a boxed int32, and JsonSerializer.SerializeToNode calls UnboxOnWrite which can't directly unbox an int32.

The fix: convert defaultValue to the target type before serializing:

Fixes #60019 (in this specific format)

@minaxi98 minaxi98 requested a review from a team as a code owner April 4, 2026 10:06
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Apr 4, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 4, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Thanks for your PR, @minaxi98. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openapi/v1.json is broken when DefaultParameterValue literal argument is not properly assigned.

1 participant