I'm trying to upload JSON to an Azure blob via a memory stream. When I call UploadAsync my application hangs. If I move the UploadAsync call outside the StreamWriter curly brackets I get a System.ObjectDisposedException: 'Cannot access a closed Stream.' exception. How can I stream the JSON to the blob?
var blobClient = new BlobClient(new Uri(storageUri), options);
var serializer = JsonSerializer.Create(this.serializerSettings);
using (var stream = new MemoryStream())
{
using (var writer = new StreamWriter(stream))
{
serializer.Serialize(writer, job);
await blobClient.UploadAsync(stream, overwrite: true, cancellationToken: cancellationToken);
}
}