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.
Let's see the difference between
get
andcreate
first to understand the problem.Get operation Before this method return, we already extract the data from
message.Response.ContentStream
So when we return as
return Response.FromValue(value, message.Response);
, we already get the value. Though we returnmessage.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 readmessage.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, themessage.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 getnull
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