From 6ed8048f8120da641171e127d777cb56989d3429 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 19 May 2026 15:32:08 -0700 Subject: [PATCH 1/2] fix: [http-client-csharp] wrap BinaryData with BinaryContent.Create in MethodParameterSegments navigation When MethodParameterSegments navigation resolves to a BinaryData property, the expression was passed directly as a BinaryContent protocol argument without wrapping. This caused a CS1503 compilation error. Wrap the resolved property expression with RequestContentApiSnippets.Create() when the protocol parameter is a content parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Providers/ScmMethodProviderCollection.cs | 12 ++++- .../ScmMethodProviderCollectionTests.cs | 45 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs index c85805768e9..fb2ad27ddd8 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs @@ -804,7 +804,17 @@ private IReadOnlyList GetProtocolMethodArguments(Dictionary [inputClient], inputModels: () => [streamModel]); + + var client = ScmCodeModelGenerator.Instance.TypeFactory.CreateClient(inputClient); + Assert.IsNotNull(client); + + var methodCollection = new ScmMethodProviderCollection(serviceMethod, client!); + var convenienceMethod = methodCollection.FirstOrDefault( + m => m.Signature.Parameters.Any(p => p.Name == "stream") && m.Signature.Name == "Send"); + Assert.IsNotNull(convenienceMethod); + + var methodBody = convenienceMethod!.BodyStatements!.ToDisplayString(); + // Verify that BinaryContent.Create() wraps the property access + Assert.IsTrue(methodBody.Contains("BinaryContent.Create(stream.Body)"), + $"Expected 'BinaryContent.Create(stream.Body)' in method body but got: {methodBody}"); + } + [Test] public async Task MissingOperationParamsResultInNamedArgsForSubsequent() { From e5cca811526c466af73de50fb8a90993b448224d Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 19 May 2026 15:32:16 -0700 Subject: [PATCH 2/2] chore: [http-client-csharp] regenerate Sample-TypeSpec after BinaryContent fix Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Sample-TypeSpec/src/Generated/SampleTypeSpecClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/SampleTypeSpecClient.cs b/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/SampleTypeSpecClient.cs index 659c42158d9..793f3eb27a1 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/SampleTypeSpecClient.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/SampleTypeSpecClient.cs @@ -334,7 +334,7 @@ public virtual ClientResult NoContentType(Wrapper info, Cancella { Argument.AssertNotNull(info, nameof(info)); - ClientResult result = NoContentType(info.P2, info.P1, info.Action, cancellationToken.ToRequestOptions()); + ClientResult result = NoContentType(info.P2, info.P1, BinaryContent.Create(info.Action), cancellationToken.ToRequestOptions()); return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); } @@ -347,7 +347,7 @@ public virtual async Task> NoContentTypeAsync(Wrapp { Argument.AssertNotNull(info, nameof(info)); - ClientResult result = await NoContentTypeAsync(info.P2, info.P1, info.Action, cancellationToken.ToRequestOptions()).ConfigureAwait(false); + ClientResult result = await NoContentTypeAsync(info.P2, info.P1, BinaryContent.Create(info.Action), cancellationToken.ToRequestOptions()).ConfigureAwait(false); return ClientResult.FromValue((RoundTripModel)result, result.GetRawResponse()); }