Skip to content

Pass ModelReaderWriterContext in generated TryResolve{Property}Array helpers#10839

Merged
jorgerangel-msft merged 5 commits into
mainfrom
copilot/fix-tryresolve-property-array-methods
May 29, 2026
Merged

Pass ModelReaderWriterContext in generated TryResolve{Property}Array helpers#10839
jorgerangel-msft merged 5 commits into
mainfrom
copilot/fix-tryresolve-property-array-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

The TryResolve{Property}Array helpers were emitting ModelReaderWriter.Write(collection, options) without the ModelReaderWriterContext argument, breaking AOT-trimmed builds (e.g. OpenAI) where the context-less overload isn't preserved.

Changes

  • ModelReaderWriterOptionsSnippets.cs: Added a new JsonFormatProperty snippet that returns the ModelReaderWriterOptions.Json static property.
  • MrwSerializationTypeDefinition.Dynamic.cs: In BuildTryResolveArrayMethod, append ModelReaderWriterContextSnippets.Default to the ModelReaderWriter.Write invocation, mirroring the pattern already used in BuildPersistableModelWriteCoreMethodBody and the XML serialization path. Also simplified the options argument to use the new ModelReaderWriterOptionsSnippets.JsonFormatProperty snippet instead of new ModelReaderWriterOptions("J").
  • Test baseline: Update PropagateModelListPropertyHelperMethods.cs to expect the third argument and the ModelReaderWriterOptions.Json static.

Generated output now matches the rest of the emitter:

global::System.BinaryData data = global::System.ClientModel.Primitives.ModelReaderWriter.Write(
    ActiveP1(),
    global::System.ClientModel.Primitives.ModelReaderWriterOptions.Json,
    global::Sample.SampleContext.Default);

…Property}Array

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TryResolve{Property}Array methods to include missing argument Pass ModelReaderWriterContext in generated TryResolve{Property}Array helpers May 29, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label May 29, 2026
Copilot AI requested a review from jorgerangel-msft May 29, 2026 16:37
Comment thread .chronus/changes/fix-tryresolve-array-mrw-context-2026-5-29-16-34-44.md Outdated
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 29, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10839

commit: e43c738

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@jorgerangel-msft
Copy link
Copy Markdown
Contributor

@copilot there are CI failures. We need to regenerate all the test libraries and ensure all tests pass

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 29, 2026

@copilot there are CI failures. We need to regenerate all the test libraries and ensure all tests pass

Regenerated the test libraries in e43c738Sample-TypeSpec's DynamicModel.Serialization.cs now emits the context argument and ModelReaderWriterOptions.Json. The project builds and the full generator test suite passes (1343 ClientModel tests + Spector tests, 0 failures).

Copilot AI requested a review from jorgerangel-msft May 29, 2026 18:03
@jorgerangel-msft jorgerangel-msft marked this pull request as ready for review May 29, 2026 19:02
@jorgerangel-msft jorgerangel-msft requested a review from m-nash as a code owner May 29, 2026 19:02
@jorgerangel-msft jorgerangel-msft added this pull request to the merge queue May 29, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 29, 2026
@jorgerangel-msft jorgerangel-msft added this pull request to the merge queue May 29, 2026
Merged via the queue into main with commit 8b0fcf3 May 29, 2026
29 checks passed
@jorgerangel-msft jorgerangel-msft deleted the copilot/fix-tryresolve-property-array-methods branch May 29, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TryResolve{Property}Array methods generate ModelReaderWriter.Write calls with missing arg in OpenAI

3 participants