Skip to content

Fix MockTemplateInfo for System.Text.Json serialization#10066

Merged
lewing merged 1 commit intodotnet:mainfrom
lewing:fix-mock-tags-stj
Mar 27, 2026
Merged

Fix MockTemplateInfo for System.Text.Json serialization#10066
lewing merged 1 commit intodotnet:mainfrom
lewing:fix-mock-tags-stj

Conversation

@lewing
Copy link
Copy Markdown
Member

@lewing lewing commented Mar 27, 2026

Problem

After the Newtonsoft.Json → System.Text.Json migration (#9956), MockTemplateInfo's explicit ITemplateInfo.Tags and ITemplateInfo.CacheParameters implementations throw NotImplementedException. Newtonsoft never visited these during serialization, but System.Text.Json walks all interface properties when serializing, causing TemplateDiscoveryMetadata.ToJObject() to crash:

System.NotImplementedException : The method or operation is not implemented.
  at MockTemplateInfo.ITemplateInfo.get_Tags()
  at System.Text.Json.Serialization...JsonPropertyInfo`1.GetMemberAndWriteJson

This breaks all CacheSearchCoordinatorTests in the SDK CI (sdk#53613).

Fix

Return empty dictionaries instead of throwing. Both properties are [Obsolete] — the mock's real tag data lives in the TagsCollection property.

@lewing lewing requested a review from a team as a code owner March 27, 2026 19:08
After the Newtonsoft.Json → System.Text.Json migration (dotnet#9956),
MockTemplateInfo's explicit ITemplateInfo.Tags and CacheParameters
implementations throw NotImplementedException. Newtonsoft never hit
these during serialization, but System.Text.Json walks all interface
properties, causing TemplateDiscoveryMetadata.ToJObject() to crash
in the SDK's CacheSearchCoordinatorTests.

Return empty dictionaries instead of throwing. Both properties are
[Obsolete] and the mock's real data lives in TagsCollection.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lewing lewing enabled auto-merge March 27, 2026 20:50
@lewing lewing merged commit 8076e34 into dotnet:main Mar 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants