兩天前,在Visual Studio 2013上通過NuGet安裝了 Windows Azure Storage 3.0.1.0 用戶端類庫,該版本是12月份剛剛更新的,如下圖所示。 但是在調用 CreateIfNotExists() 通過本地的 Windows Storage Emulator 2.2.0.0 建立Windows Azure Table時,總是抛出異常 : A first chance exception of type 'Microsoft.WindowsAzure.Storage.StorageException' occurred in Microsoft.WindowsAzure.Storage.dll. Additional Information : The remote server returned an error : (400) Bad Request。所使用建立代碼非常簡單:
// Creates Changeset table if not exists
var client = StorageAccount.CreateCloudTableClient();
table = client.GetTableReference(tableName);
table.CreateIfNotExists();

不應該是Windows Azure Storage APIs使用的問題。進一步檢查給出的異常資訊,發現其Response.StatusCode = BadRequest; Response.StatusDescription = The value for one of the HTTP headers is not in the correct format。在網上搜尋了一下,已經有人報過類似的問題,但原因也是多種,比如:Table名字中包含非法字元的等。
此外,也有人提到有可能是Azure Storage API和Emulator不相容的問題,于是将正在使用的Windows Azure Storage由3.0.1.0降到一個月前的版本 2.1.0.4,在安裝了2.1.0.4後,同樣的代碼運作一切正常。看來确實是 Windows Azure Storage 3.0.1.0 和 Windows Azure Storage Enumlator 2.2.0.0 的相容問題,解決的辦法就是将Storage類庫降級到較早的版本。不僅是3.0.1.0,在我的環境中Windows Azure Storage 3.0.0 也有類似與Storage Emulator的相容的問題。