microsoft / microsoft/vs-streamjsonrpc

Make RequestIdSTJsonConverter public for AOT/trimming compatibility

Open
#1,407 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
937
Forks
178
Avg merge
3d 1h
Merged PRs (30d)
28

Description

Problem

When using SystemTextJsonFormatter with custom JsonSerializerOptions that use TypeInfoResolverChain (the AOT-safe approach), RequestId serialization fails at runtime because:

  1. RequestIdSTJsonConverter is internal, so consumers cannot reference it
  2. [JsonSerializable(typeof(RequestId))] fails with SYSLIB1220 because RequestId has [JsonConverter(typeof(RequestIdSTJsonConverter))] and that converter is inaccessible (CS0122)
  3. MassageUserDataSerializerOptions adds the converter via options.Converters.Add(), but in AOT mode without a reflection-based fallback resolver, Converters alone cannot produce JsonTypeInfo<RequestId> — the converter is unreachable

This surfaces as a NotSupportedException when StandardCancellationStrategy tries to serialize a $/cancelRequest notification containing a RequestId.

Suggested Fix

Make RequestIdSTJsonConverter public so consumers can either:

  • Use [JsonSerializable(typeof(RequestId))] in their source-generated contexts
  • Reference the converter directly when building custom IJsonTypeInfoResolver implementations

Additionally, MassageUserDataSerializerOptions could be updated to add entries to TypeInfoResolverChain (not just Converters), so the formatter is self-sufficient in AOT mode even when users provide custom options.

Workaround

We currently duplicate the converter logic and wire it via a custom IJsonTypeInfoResolver + JsonMetadataServices.CreateValueInfo<RequestId>(). See: https://github.com/github/copilot-sdk/pull/783

Related

  • #840 — RequestId AOT crash (Newtonsoft-based, same class of problem)
  • #1230 — AOT NotSupportedException with IAsyncEnumerable structs (same root cause pattern: internal converters + AOT)

cc @AArnott

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting RequestIdSTJsonConverter and MassageUserDataSerializerOptions, then trace how StandardCancellationStrategy serializes RequestId with custom TypeInfoResolverChain options. Compare the proposed public-converter approach with the resolver workaround in copilot-sdk PR 783. Done means the selected AOT/trimming path is implemented and RequestId serialization works without a reflection-based fallback.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.