Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
140 stars 160 forks source link

Any operation except get just not working in cadl-ranch context #4878

Open pshao25 opened 1 week ago

pshao25 commented 1 week ago

Let's see the difference between get and create first to understand the problem.

Get operation Before this method return, we already extract the data from message.Response.ContentStream

using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

So when we return as return Response.FromValue(value, message.Response);, we already get the value. Though we return message.Response which is now available in this method, it will be disposed when code goes out of this method. Since we already get the value, we will not read message.Response any more so that we are not facing problem.

Create operation This is a long running operation, which does not process the response like get operation. Instead it just returns message.Response to let its caller to process, at which point, the message.Response is disposed.

To summarize which cases would have problem: as long as message.Response is not processed after it is received and it is returned to let caller process, we will get null from this response.

What operations have problem: all the operations except get.

It's a known issue. Related issues: https://github.com/Azure/autorest.csharp/issues/3707 https://github.com/Azure/autorest.csharp/issues/1571