Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Setting blob metadata with empty string VALUE but valid key throws exception #828

Open
dpoole73 opened this issue Nov 30, 2018 · 3 comments · May be fixed by #1008
Open

Setting blob metadata with empty string VALUE but valid key throws exception #828

dpoole73 opened this issue Nov 30, 2018 · 3 comments · May be fixed by #1008

Comments

@dpoole73
Copy link

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(RESTCommand1 cmd, Uri uri, UriQueryBuilder builder, HttpContent cnt, Nullable1 serverTimeout, OperationContext ctx) at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand1 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

@kfarmer-msft
Copy link
Contributor

Thanks, @dpoole73 --

I've verified with the server folks. I'll plan on adding this.

@ansario
Copy link

ansario commented Jan 22, 2019

Duplicate of #592

@jwilson-proag
Copy link

jwilson-proag commented Jul 15, 2021

Is there any update on this? This issue was reported almost 3 years ago and a PR was put in over a year ago to fix. Can we get that PR pushed through so I no longer have to check string.IsNullOrEmpty() every time I add metadata to a blob?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants