Skip to content

build(server): ban the HTTP JSON helpers that serialize by reflection - #556

Merged
pdevito3 merged 2 commits into
mainfrom
build/chk65-json-helpers
Dec 4, 2026
Merged

pdevito3 merged 2 commits into
mainfrom
build/chk65-json-helpers

Conversation

@pdevito3

@pdevito3 pdevito3 commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Summary

The Server and the BFF now ban, with RS0030, the HTTP JSON helpers that serialize by reflection: the overloads of JsonContent.Create, the HttpClient JSON calls, ReadFromJsonAsync, WriteAsJsonAsync, Results.Json, and TypedResults.Json that take no JsonTypeInfo or context. Each message names the fix: pass a JsonTypeInfo from a [JsonSerializable] context.

  • 53 banned overloads per project. The IDs come from the 10.0.15 reference assemblies through Roslyn, not by hand.
  • The BFF had no banned API analyzer, so this adds the package reference and its own BannedSymbols.txt.
  • ManagementProblem.cs now writes through a ManagementProblemJson context. The 8 refusal bodies are byte-for-byte the same as before.

Why

An agent eval on a model provider task showed that agents copy reflection JSON from existing code, and no check caught it. The rule is in docs/backend/source-generators.md.

Test plan

  • dotnet build FullstackTemplate.slnx: 0 warnings, 0 errors
  • A planted JsonContent.Create(new { ... }) fails the build with RS0030 in the Server and in the BFF
  • tests/FullstackTemplate.Bff.Tests: 575 of 575 pass

… (CHK-65)

The Server and the BFF ban the JsonContent, HttpClient, HttpContent, HttpRequest, HttpResponse, Results, and TypedResults JSON overloads that take no JsonTypeInfo or context. The BFF problem body now writes through ManagementProblemJson, with the same bytes as before.
@pdevito3
pdevito3 merged commit 511fd44 into main Dec 4, 2026
23 checks passed
@pdevito3
pdevito3 deleted the build/chk65-json-helpers branch December 4, 2026 21:04
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.

1 participant