Skip to content

Fix dictionary deserialization crash on $-prefixed keys#9983

Open
haiyuazhang wants to merge 2 commits intomicrosoft:mainfrom
haiyuazhang:fix/dollar-prefix-dictionary-deserialization
Open

Fix dictionary deserialization crash on $-prefixed keys#9983
haiyuazhang wants to merge 2 commits intomicrosoft:mainfrom
haiyuazhang:fix/dollar-prefix-dictionary-deserialization

Conversation

@haiyuazhang
Copy link
Member

Fixes #9982

haiyuazhang and others added 2 commits March 11, 2026 02:04
Add TryReadComplexType overload for IReadOnlyDictionary<string, T> that
manually reads dictionary entries via Utf8JsonReader, bypassing the
default System.Text.Json dictionary converter which rejects property
names starting with '$' when ReferenceHandler is enabled.

This fixes a crash when generating SDKs from specs with OData parameters
(e.g. \) that appear as dictionary keys in example values.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a \ key to the existing PutStorageTask example test data and
assert it deserializes correctly. Without the fix, this reproduces the
JsonException: 'Properties that start with \$ are not allowed in types
that support metadata.'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Mar 10, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 10, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@9983

commit: 24e15ab

@github-actions
Copy link
Contributor

No changes needing a change description found.

return true;
}

public static bool TryReadComplexType<T>(this ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref IReadOnlyDictionary<string, T>? value)
Copy link
Contributor

Choose a reason for hiding this comment

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

this will also be applied for discriminatedSubtypes, since we deserialize into ireadonlydictionary. I kicked off a regen preview pipeline to make sure there isn't any unexpected regression https://dev.azure.com/azure-sdk/internal/_build/results?buildId=5994632&view=results

Copy link
Contributor

Choose a reason for hiding this comment

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

@haiyuazhang it looks like the regen preview pipeline failed https://dev.azure.com/azure-sdk/internal/_build/results?buildId=5994632&view=logs&j=bb16106d-22e7-5110-6a98-db4aff7298af&t=ed160a59-989c-5a64-b845-833612591558. Can we please try running the regen preview script locally against the failing library to see if it's related to this change, or not?

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

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Generator crashes on specs with $-prefixed OData parameter names in example values

2 participants