Skip to content

Make RequestIdSTJsonConverter public for AOT/trimming compatibility #1407

@PureWeen

Description

@PureWeen

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: github/copilot-sdk#783

Related

cc @AArnott

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions