Azure / Azure/azure-quickstart-templates

When trying to retrieve all storage accounts in a region using C# Fluent SDK - we got once the following error: System.InvalidOperationException: The stream was already consumed. It cannot be read again.

Open
#7,122 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Bicep
Stars
14.9k
Forks
16.2k
Avg merge
6d 21h
Merged PRs (30d)
6

Description

Hi,
We have a project with .NET Framework 4.7.2 as the target.
In order to retrieve all storage accounts in a region - we run the following c# code (implemented using Fluent SDK):

```
public async Task> GetStorageAccountsAsync(string location)
{
List azureStorageAccounts = new List();
IPagedCollection storageAccounts = await m_azure.StorageAccounts.ListAsync();
foreach (IStorageAccount storageAccount in storageAccounts)
{
if (AzureGenericExtensions.AreLocationsEqual(storageAccount.Region.Name, location))
{
azureStorageAccounts.Add(new AzureStorageAccount(storageAccount.Id, storageAccount.Name,
storageAccount.SkuType != null && storageAccount.SkuType.Name == SkuName.PremiumLRS,
storageAccount.Kind == Kind.BlobStorage));
}
}

return azureStorageAccounts;
}
```

The error has not been reproduced.

Here is the stack trace of the error:

```
Error message = 'The stream was already consumed. It cannot be read again.'.,"System.InvalidOperationException Void PrepareContent() System.InvalidOperationException: The stream was already consumed. It cannot be read again.
at System.Net.Http.StreamContent.PrepareContent()
at System.Net.Http.StreamContent.SerializeToStreamAsync(Stream stream, TransportContext context)
at System.Net.Http.HttpContent.LoadIntoBufferAsync(Int64 maxBufferSize)
at System.Net.Http.HttpClient.StartContentBuffering(HttpRequestMessage request, CancellationTokenSource cancellationTokenSource, TaskCompletionSource`1 tcs, HttpResponseMessage response)
at System.Net.Http.HttpClient.<>c__DisplayClass55_0.b__0(Task`1 task)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Azure.Management.Storage.Fluent.StorageAccountsOperations.d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Azure.Management.Storage.Fluent.StorageAccountsOperationsExtensions.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Azure.Management.Storage.Fluent.StorageAccountsImpl.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.PagedCollection`2.d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.PagedCollection`2.d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.TopLevelModifiableResources`5.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Zerto.Zvm.Platform.PublicCloud.AzureProxy.Accessors.StorageAccountsAccessor.d__6.MoveNext() in E:\glenlivet_private_execution-ci\dev\system\Zvm\Platform\PublicCloud\AzureProxy\Accessors\StorageAccountsAccessor.cs:line 77
```

Could you please help with this issue?

Thanks.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at StorageAccountsAccessor.GetStorageAccountsAsync, especially line 77 and the call to m_azure.StorageAccounts.ListAsync(), then compare the stack trace with the Fluent SDK storage-account operations. Done would require a reproducible failure and a confirmed SDK or request-handling change, neither of which is provided here.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.