Setting blob metadata with empty string VALUE but valid key throws exception #828
Description
openedon Nov 30, 2018
Which service(blob, file, queue, table) does this issue concern?
Blob
Which version of the SDK was used?
9.3
Which platform are you using? (ex: .NET Core 2.1)
Net Core 2.1
What problem was encountered?
An exception (parameter cannot be empty string) when calling blobReference.SetMetadataAsync() to set blob metadata to the dictionary that I set on the blob reference.
I set the metadata properties like this
blobReference.Metadata.Add("PropertyName", value);
if the value of the parameter is null or empty string, an exception is thrown:
Microsoft.WindowsAzure.Storage.StorageException: The argument must not be empty string. ---> System.ArgumentException: The argument must not be empty string.
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpRequestMessageFactory.AddMetadata(StorageRequestMessage request, String name, String value)
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpRequestMessageFactory.AddMetadata(StorageRequestMessage request, IDictionary2 metadata) at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.<>c__DisplayClass135_0.<SetMetadataImpl>b__0(RESTCommand
1 cmd, Uri uri, UriQueryBuilder builder, HttpContent cnt, Nullable1 serverTimeout, OperationContext ctx) at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand
1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
How can we reproduce the problem in the simplest way?
Get a cloud blob blob reference and call:
blobReference.Metadata.Add("PropertyName", null);
blobReference.SetMetadataAsync();
or
blobReference.Metadata.Add("PropertyName", "");
blobReference.SetMetadataAsync();
Have you found a mitigation/solution?
I believe this is a bug the the code here: https://github.com/Azure/azure-storage-net/blob/master/Lib/Common/Shared/Protocol/HttpRequestMessageFactory.cs#L203
it checks for the value being null but should be checking the name for null instead. It later goes on to construct the header name from the name so clearly was intended to check the name rather than value