Extra Slash in Uri Causes BlockBlobRestClient Upload Failure: InvalidQueryParameterValue

August 05, 2025
Cover Image

It's kind of crazy how long I spent trying to figure this error out. I thought it was because of a problem with AzureDefaultCredentials but it turned out to be an extra slash in a URL.

The Failing Code

I was trying to upload a file to an Azure Storage Blob. Nothing that I haven't done 50 trillion times using the SDK but this time it was failing.

Here's the code:

Console.WriteLine($"Using Azure Managed Identity for Azure Blob Storage connection.");

var azureCredential = new DefaultAzureCredential();
var accountName = config.GetStringThrowIfNullOrEmpty("AzureStorage:AccountName");

Console.WriteLine($"Azure Storage Account Name: {accountName}");            

var blobServiceUri = new Uri($"https://{accountName}.blob.core.windows.net");

Console.WriteLine($"Blob Service URI: {blobServiceUri}");
Console.WriteLine($"Azure Credential: {azureCredential}");

services.AddSingleton(new BlobContainerClient(
    new Uri($"{blobServiceUri}/{ApiConstants.AzureBlobContainerName}"),
    azureCredential));

The Error

When I went to upload using the BlobContainerClient I got the following error buried in a gigantic error message. Here's the error:

<Error>
    <Code>InvalidQueryParameterValue</Code>
    <Message>
        Value for one of the query parameters specified in the request URI is invalid.
        RequestId:4d74da06-301e-002c-5e6d-dcd23e000000
        Time:2025-06-13T14:15:30.9293230Z
    </Message>
    <QueryParameterName>comp</QueryParameterName>
    <QueryParameterValue />
    <Reason />
</Error>

And because I hope someone who also faces this can find this post on the internet(s), here's the full, giant error blob:

fail: PowerpointUtil.Api.AzureStorage.BlobUploader[0]
      Request failed while uploading audio file '001.mp3' to blob.
      Azure.RequestFailedException: Value for one of the query parameters specified in the request URI is invalid.
      RequestId:4d74da06-301e-002c-5e6d-dcd23e000000
      Time:2025-06-13T14:15:30.9293230Z
      Status: 400 (Value for one of the query parameters specified in the request URI is invalid.)
      ErrorCode: InvalidQueryParameterValue
      
      Additional Information:
      QueryParameterName: comp
      QueryParameterValue: 
      Reason: 
      
      Content:
      <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidQueryParameterValue</Code><Message>Value for one of the query parameters specified in the request URI is invalid.
      RequestId:4d74da06-301e-002c-5e6d-dcd23e000000
      Time:2025-06-13T14:15:30.9293230Z</Message><QueryParameterName>comp</QueryParameterName><QueryParameterValue /><Reason /></Error>
      
      Headers:
      Server: Microsoft-HTTPAPI/2.0
      x-ms-request-id: 4d74da06-301e-002c-5e6d-dcd23e000000
      x-ms-client-request-id: 5c1dbfa7-f1c1-4d83-813f-31e20193a98e
      x-ms-error-code: InvalidQueryParameterValue
      Date: Fri, 13 Jun 2025 14:15:30 GMT
      Content-Length: 351
      Content-Type: application/xml
      
         at Azure.Storage.Blobs.BlockBlobRestClient.UploadAsync(Int64 contentLength, Stream body, Nullable`1 timeout, Byte[] transactionalContentMD5, String blobContentType, String blobContentEncoding, String blobContentLanguage, Byte[] blobContentMD5, String blobCacheControl, IDictionary`2 metadata, String leaseId, String blobContentDisposition, String encryptionKey, String encryptionKeySha256, Nullable`1 encryptionAlgorithm, String encryptionScope, Nullable`1 tier, Nullable`1 ifModifiedSince, Nullable`1 ifUnmodifiedSince, String ifMatch, String ifNoneMatch, String ifTags, String blobTagsString, Nullable`1 immutabilityPolicyExpiry, Nullable`1 immutabilityPolicyMode, Nullable`1 legalHold, Byte[] transactionalContentCrc64, String structuredBodyType, Nullable`1 structuredContentLength, CancellationToken cancellationToken)
         at Azure.Storage.Blobs.Specialized.BlockBlobClient.UploadInternal(Stream content, BlobHttpHeaders blobHttpHeaders, IDictionary`2 metadata, IDictionary`2 tags, BlobRequestConditions conditions, Nullable`1 accessTier, BlobImmutabilityPolicy immutabilityPolicy, Nullable`1 legalHold, IProgress`1 progressHandler, UploadTransferValidationOptions transferValidationOverride, String operationName, Boolean async, CancellationToken cancellationToken)
         at Azure.Storage.Blobs.Specialized.BlockBlobClient.<>c__DisplayClass65_0.<<GetPartitionedUploaderBehaviors>b__0>d.MoveNext()
      --- End of stack trace from previous location ---
         at Azure.Storage.PartitionedUploader`2.UploadInternal(Stream content, Nullable`1 expectedContentLength, TServiceSpecificData args, IProgress`1 progressHandler, Boolean async, CancellationToken cancellationToken)
         at Azure.Storage.Blobs.BlobClient.StagedUploadInternal(Stream content, BlobUploadOptions options, Boolean async, CancellationToken cancellationToken)
         at PowerpointUtil.Api.AzureStorage.BlobUploader.UploadAudioFileAsync(SlideItem item, Stream fileStream) in /src/PowerpointUtil.Api/AzureStorage/BlobUploader.cs:line 371
fail: PowerpointUtil.Api.AzureStorage.BlobUploader[0]
      Error Code: InvalidQueryParameterValue
fail: PowerpointUtil.Api.AzureStorage.BlobUploader[0]
      Status: 400
fail: PowerpointUtil.Api.AzureStorage.BlobUploader[0]
      Message: Value for one of the query parameters specified in the request URI is invalid.
      RequestId:4d74da06-301e-002c-5e6d-dcd23e000000
      Time:2025-06-13T14:15:30.9293230Z
      Status: 400 (Value for one of the query parameters specified in the request URI is invalid.)
      ErrorCode: InvalidQueryParameterValue
      
      Additional Information:
      QueryParameterName: comp
      QueryParameterValue: 
      Reason: 
      
      Content:
      <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidQueryParameterValue</Code><Message>Value for one of the query parameters specified in the request URI is invalid.
      RequestId:4d74da06-301e-002c-5e6d-dcd23e000000
      Time:2025-06-13T14:15:30.9293230Z</Message><QueryParameterName>comp</QueryParameterName><QueryParameterValue /><Reason /></Error>
      
      Headers:
      Server: Microsoft-HTTPAPI/2.0
      x-ms-request-id: 4d74da06-301e-002c-5e6d-dcd23e000000
      x-ms-client-request-id: 5c1dbfa7-f1c1-4d83-813f-31e20193a98e
      x-ms-error-code: InvalidQueryParameterValue
      Date: Fri, 13 Jun 2025 14:15:30 GMT
      Content-Length: 351
      Content-Type: application/xml

It's All Because of an Extra Slash

Ultimately, this had hardly anything to do with Azure Storage. It's all about some string logic in the Uri class in C#.

To make it a little easier to see, here's a couple of unit tests that I created to reproduce the problem.

[Fact]
public void ExtraSlashes()
{
    var accountName = "myacccountname";
    var blobServiceUri = new Uri($"https://{accountName}.blob.core.windows.net");

    var containerName = "mycontainer";

    WriteLine($"Azure Storage Account Name: {accountName}");
    WriteLine($"Blob Service URI: {blobServiceUri}");
    WriteLine($"Container name: {containerName}");

    var containerUri = new Uri($"{blobServiceUri}/{containerName}");

    WriteLine($"Blob Container Client URI: {containerUri}");
}

[Fact]
public void WithoutExtraSlashes()
{
    var accountName = "myacccountname";
    var blobServiceUri = new Uri($"https://{accountName}.blob.core.windows.net");

    var containerName = "mycontainer";

    WriteLine($"Azure Storage Account Name: {accountName}");
    WriteLine($"Blob Service URI: {blobServiceUri}");
    WriteLine($"Container name: {containerName}");

    var containerUri = new Uri($"{blobServiceUri}{containerName}");

    WriteLine($"Blob Container Client URI: {containerUri}");
}

Looking at this code, it's super hard to see the problem. It's all about how I created the containerUri value. The block of code below shows you exactly what the difference is — it's that "/" in the first string.

// slash between blob service URI and container name causes an error
var error = new Uri($"{blobServiceUri}/{containerName}");

// no slash between blob service URI and container name does not cause an error
var noError = new Uri($"{blobServiceUri}{containerName}");

The difference ends up being between

https://myacccountname.blob.core.windows.net/mycontainer

and

https://myacccountname.blob.core.windows.net//mycontainer

That extra slash version doesn't cause BlobContainerClient any heartache until it's asked to do some work against the actual Azure Storage Blob service. And even then, it's not the BlobContainerClient that's causing the error. It happily sends the requests to the backend service and then the service is the one that throws the error.

Summary

In the end, this bug was all about a silent, sneaky extra slash in the URL — something that looked harmless but led to a confusing and misleading error deep in the Azure Blob Storage stack. If you’re working with URIs in C#, especially when constructing them via string interpolation, it pays to be meticulous about trailing slashes.

I hope this helps.

-Ben

Categories: azure