private async Task<NonSeekableStream> WriteMessageCoreAsync(
S101Message message, CancellationToken cancellationToken)
{
this.AssertNotDisposed();
if (message == null)
{
throw new ArgumentNullException(nameof(message));
}
if ((this.stream != null) && this.stream.CanWrite)
{
throw new InvalidOperationException(
"DisposeAsync() has not been called on the payload stream of the previous message.");
}
this.stream = await MessageEncodingStream.CreateAsync(this.writeBuffer, message, cancellationToken);
if (!message.CanHavePayload)
{
await this.stream.DisposeAsync(cancellationToken);
this.stream = null;
}
return this.stream;
}