Azure storage files ShareClient throwing an exception

810 views Asked by At

Created a sample console application and I am trying to connect to Azure file storage using this code.

var connectionString = "DefaultEndpointsProtocol=https;AccountName=<account-name>;AccountKey=<account-key>;EndpointSuffix=core.windows.net;";            
        var shareClient = new ShareClient(connectionString, "testfileshare");
        shareClient.CreateIfNotExists();

the share name "testfileshare" exists in the account and "CreateIfNotExists()" method call throwing AggregateException with message

"Retry failed after 6 tries" with InnerException message "The underlying connection was closed: An unexpected error occurred on a send."

I am using Azure.Storage.Files.Shares, 12.4.0 version. Target framework is .NET4.6.2. Tried updating target framework to .NET4.7.2 but getting same error.

Why am I getting this error?

Adding stack trace:

     at Azure.Core.Pipeline.RetryPolicy.<ProcessAsync>d__11.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Core.Pipeline.RetryPolicy.Process(HttpMessage message, ReadOnlyMemory`1 pipeline)
   at Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage message, ReadOnlyMemory`1 pipeline)
   at Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.Process(HttpMessage message, ReadOnlyMemory`1 pipeline)
   at Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage message, ReadOnlyMemory`1 pipeline)
   at Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.Process(HttpMessage message, ReadOnlyMemory`1 pipeline)
   at Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage message, ReadOnlyMemory`1 pipeline)
   at Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.Process(HttpMessage message, ReadOnlyMemory`1 pipeline)
   at Azure.Core.Pipeline.HttpPipeline.Send(HttpMessage message, CancellationToken cancellationToken)
   at Azure.Storage.Files.Shares.FileRestClient.Share.<CreateAsync>d__0.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Storage.Files.Shares.ShareClient.<CreateInternal>d__31.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Storage.Files.Shares.ShareClient.<CreateIfNotExistsInternal>d__34.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Storage.Files.Shares.ShareClient.CreateIfNotExists(IDictionary`2 metadata, Nullable`1 quotaInGB, CancellationToken cancellationToken)
   at FileStorageTest.Program.Main(String[] args) in C:\Tests\FileStorageTest\FileStorageTest\Program.cs:line 24
1

There are 1 answers

0
PSR On

I have found the issue. When I add Azure.Storage.Files.Shares package reference from nuget I observed that in project file Azure.Core reference is adding from "net461" folder and others are adding from "netstandard2.0" folder and my application target framework is "Net4.6.2"

This causing the issue. When I manually changed Azure.Core reference path to "netstandard2.0" it is working fine.

    <Reference Include="Azure.Core, Version=1.5.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL">
<!--<HintPath>..\packages\Azure.Core.1.5.0\lib\net461\Azure.Core.dll</HintPath>-->
      <HintPath>..\packages\Azure.Core.1.5.0\lib\netstandard2.0\Azure.Core.dll</HintPath>
    </Reference>

I have reproduced this issue by upgrading "Azure.Storage.Files.Shares" package. I do not know whether it is VS issue or nuget issue.