diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/Utf8JsonReaderExtensions.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/Utf8JsonReaderExtensions.cs index 12e488d7c9c..00124c64137 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/Utf8JsonReaderExtensions.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/Utf8JsonReaderExtensions.cs @@ -164,9 +164,15 @@ public static bool TryReadComplexType(this ref Utf8JsonReader reader, string throw new JsonException(); } reader.Read(); + string? id = null; var result = new Dictionary(); while (reader.TokenType != JsonTokenType.EndObject) { + // Skip $id metadata (reference tracking), just like TryReadReferenceId does + if (reader.TryReadReferenceId(ref id)) + { + continue; + } var key = reader.GetString() ?? throw new JsonException("Dictionary key cannot be null"); reader.Read(); var item = reader.ReadWithConverter(options);