2014-12-02 81 views
0

當我將Azure存儲從1.8升級到4.0.1時,以下代碼不再有效。將存儲升級到4.0.1後,Azure存儲容器ListBlobs拋出Uri NULL異常

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

隨着存儲4.0.1,代碼拋出異常:

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) 

如何得到它的工作任何想法?

我知道我可以使用帳戶和accountkey來創建憑據來訪問容器和列表blob,但我想知道如何做到這一點只與SAS的blob路徑。

任何建議將不勝感激。

回答

2

您在下面提供的SAS令牌是使用舊版本的Storage Client Library生成的。客戶端庫只能與REST協議的一個版本進行通信。使用舊客戶端生成的SAS令牌強制舊REST版本服務端進行操作,但新客戶端使用2014 REST版本語義來解釋響應。 由於這些REST版本之間的ListBlobs XML響應發生了重大更改,因此新客戶端庫無法正確分析該XML,因此發生中斷。

下面是關於一些變化SAS令牌可能是有用的,包括API版本參數一些更多的信息:http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/14/what-s-new-for-microsoft-azure-storage-at-teched-2014.aspx

請嘗試與客戶端庫的版本4.0.1和你的代碼再生令牌應該按預期工作。