azure-sdk-for-net: [BUG] SDK ignores AccountName in connectionstring if custom host name is used as storage

Describe the bug Related to this issue on Azurite: https://github.com/Azure/Azurite/issues/379

If a host name is used (instead of localhost or 172.0.0.1) to emulate a blob store locally, the client SDK strips off the account name in the URL’s to the storage, and the account name specified in the connection string is ignored.

Exception or Stack Trace

System.Xml.XmlException : Root element is missing.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   at System.Xml.Linq.XDocument.Load(Stream stream, LoadOptions options)
   at Azure.Storage.Blobs.BlobRestClient.Container.CreateAsync_CreateResponse(Response response)
   at Azure.Storage.Blobs.BlobRestClient.Container.CreateAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri resourceUri, PublicAccessType access, Nullable`1 timeout, IDictionary`2 metadata, String requestId, Boolean async, String operationName, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.BlobContainerClient.CreateInternal(PublicAccessType publicAccessType, IDictionary`2 metadata, Boolean async, CancellationToken cancellationToken, String operationName)
   at Azure.Storage.Blobs.BlobContainerClient.CreateIfNotExistsInternal(PublicAccessType publicAccessType, IDictionary`2 metadata, Boolean async, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.BlobContainerClient.CreateIfNotExistsAsync(PublicAccessType publicAccessType, IDictionary`2 metadata, CancellationToken cancellationToken)

If I change the connection string from azurite to 127.0.0.1 it all works fine.

To Reproduce When connection string looks like this: (127.0.0.1 is the host): AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://azurite:10000/devstoreaccount1; The generated requests look like this, which is correct: "PUT /devstoreaccount1/images?restype=container" HTTP/1.1 201

When connection string looks like this (azurite is the host name):

AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://azurite:10000/devstoreaccount1;

The generated requests look like this: "PUT /images?restype=container HTTP/1.1" 400 -

Steps to reproduce the behavior:

Code Snippet

[Fact]
public async Task CanUploadUsingHostName()
{
    var container = new BlobContainerClient(ConnectionString, "bifs");
    var ifNotExistsAsync = await container.CreateIfNotExistsAsync();
    await using var stream = File.OpenRead(@".\test\output\3ee9bc41-40ea-4d05-b180-e74bd5065622\images\00000000.jpg");
    await container.UploadBlobAsync("test.jpg", stream);
}

Expected behavior When AccountName is specified in the connection string, I would expect the client to behave the same (generate requests with the same URL’s) regardless of the host name. Especially if it is not a host name specific to Azure Blob Storage.

Setup (please complete the following information):

  • OS: All
  • IDE : All
  • Version of the Library used: 12.1.0

Additional context Stack Overflow question here: https://stackoverflow.com/questions/59615330/connecting-to-azurite-using-a-hostname-fails/59651621#59651621

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

There is an open PR looking at fixing this - https://github.com/Azure/azure-sdk-for-net/pull/10564

Hi, having the same issue here trying to test a dockerized .NET Core app in a Compose file with Azurite. Seems like a pretty big problem.

@mattschoutends, we’ll take a look at the PR