0
votes

When I was upgrading azure storage from 1.8 to 4.0.1, the following codes don't work anymore.

var myUri = new Uri(generatedURLwithSAS);
var sasContainer = new CloudBlobContainer(myUri);
var result0 = sasContainer.ListBlobs();
Console.WriteLine(result0);

With storage 4.0.1, the codes throws out Exception:

Exception Type: Microsoft.WindowsAzure.Storage.StorageException
Exception: Value cannot be null.
Parameter name: uriString
Stack Trace: 
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd,     IRetryPolicy policy, OperationContext operationContext)
at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.<>c__DisplayClassf.<ListBlobs>b__e(IContinuationToken token)at Microsoft.WindowsAzure.Storage.Core.Util.CommonUtility.<LazyEnumerable>d__0`1.MoveNext()

Exception Type: System.ArgumentNullException
Exception: Value cannot be null.
Parameter name: uriString
Stack Trace: 
at System.Uri..ctor(String uriString)
at Microsoft.WindowsAzure.Storage.Blob.Protocol.ListBlobsResponse.<ParseXml>d__0.MoveNext()
at Microsoft.WindowsAzure.Storage.Shared.Protocol.ResponseParsingBase`1.<ParseXmlAndClose>d__6.MoveNext()
at Microsoft.WindowsAzure.Storage.Shared.Protocol.ResponseParsingBase`1.<get_ObjectsToParse>d__0.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.<ListBlobsImpl>b__4a(RESTCommand`1 cmd, HttpWebResponse resp, OperationContext ctx)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ProcessEndOfRequest[T](ExecutionState`1 executionState)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)

Any idea of how to get it working ?

I know I can use account and accountkey to create credentials to access the container and list blobs, but I would like to know how to do that with only the blob path with SAS.

Any suggestion would be greatly appreciated.

1

1 Answers

2
votes

The SAS token you provided below was generated using an old version of the Storage Client Library. The client library can talk to only one version of the REST protocol. A SAS token generated using an old client enforces an old REST version service-side for operations but the new client uses 2014 REST version semantics to interpret the responses. This breaks down because there were breaking changes in the ListBlobs XML response between these REST versions, so the new client library cannot correctly parse that XML.

Here’s some more information about some of the changes to SAS tokens that might be useful, including the api-version parameter: http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/14/what-s-new-for-microsoft-azure-storage-at-teched-2014.aspx

Please try regenerating the token with version 4.0.1 of the client library and your code should work as intended.