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>
@dsplaisted
Copy link
Copy Markdown
Member

/backport to release/11.0.1xx-preview3

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Started backporting to release/11.0.1xx-preview3 (link to workflow run)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

@dsplaisted an error occurred while backporting to release/11.0.1xx-preview3. See the workflow output for details.

dsplaisted added a commit to dsplaisted/dotnet that referenced this pull request Apr 9, 2026
…J serialization

Backport of dotnet/templating#10066 to release/11.0.1xx-preview3.

After the Newtonsoft.Json to System.Text.Json migration, MockTemplateInfo's
explicit ITemplateInfo.Tags and ITemplateInfo.CacheParameters implementations
throw NotImplementedException. System.Text.Json walks all interface properties
during serialization, causing TemplateSearchCoordinator tests to crash.

Return null! instead of throwing, matching what dotnet/templating main has.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants