-
Notifications
You must be signed in to change notification settings - Fork 169
Description
Problem
When using SystemTextJsonFormatter with custom JsonSerializerOptions that use TypeInfoResolverChain (the AOT-safe approach), RequestId serialization fails at runtime because:
RequestIdSTJsonConverterisinternal, so consumers cannot reference it[JsonSerializable(typeof(RequestId))]fails with SYSLIB1220 becauseRequestIdhas[JsonConverter(typeof(RequestIdSTJsonConverter))]and that converter is inaccessible (CS0122)MassageUserDataSerializerOptionsadds the converter viaoptions.Converters.Add(), but in AOT mode without a reflection-based fallback resolver,Convertersalone cannot produceJsonTypeInfo<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
IJsonTypeInfoResolverimplementations
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
- Error getting value from 'RequestId' on net6.0-ios app #840 — RequestId AOT crash (Newtonsoft-based, same class of problem)
- Using a struct in an IAsyncEnumerable parameter with native AOT doesn't work #1230 — AOT
NotSupportedExceptionwithIAsyncEnumerablestructs (same root cause pattern: internal converters + AOT)
cc @AArnott