我有代码检查是否存在blob及其大小在我的开发机器中工作正常但是当我发布到生产服务器时它给了我例外:
blob引用的blob类型与blob的blob类型不匹配
以下是代码:
CloudStorageAccount v_StorageAccount = CloudStorageAccount.Parse(v_ConnectionString);
CloudBlobClient v_BlobClient = v_StorageAccount.CreateCloudBlobClient();
CloudBlobContainer v_Container = v_BlobClient.GetContainerReference(v_Containerstring);
CloudBlockBlob v_Blob = v_Container.GetBlockBlobReference(p_Name);
v_Blob.FetchAttributes();
我已经使用fiddler进行了测试,发现当在服务器中运行时,响应头没有任何x-ms-标签,尽管两台机器中的请求头都相同。
请求标题:
HEAD http://XXX/90f5a5f1-9f6f-46bc-bbf6-21d77b8955ed HTTP/1.1
User-Agent: Azure-Storage/8.2.0 (.NET CLR 4.0.30319.36399; Win32NT 6.2.9200.0)
x-ms-version: 2017-04-17
x-ms-client-request-id: XXX
x-ms-date: Thu, 11 Jan 2018 13:44:14 GMT
Authorization: SharedKey XXX:XXX
Host: XXX
开发机器中的响应:
HTTP/1.1 200 OK
Content-Length: 504014
Content-Type: application/octet-stream
Content-MD5: /i5aFVWYlPqZjHvU+gxcbw==
Last-Modified: Wed, 13 Dec 2017 20:22:02 GMT
Accept-Ranges: bytes
ETag: "0x8D542672BB913FD"
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 04155a59-001e-000d-58e5-8ab906000000
x-ms-version: 2017-04-17
x-ms-lease-status: unlocked
x-ms-lease-state: available
x-ms-blob-type: BlockBlob
x-ms-server-encrypted: false
Date: Thu, 11 Jan 2018 14:04:56 GMT
生产服务器中的响应:
HTTP/1.1 200 OK
Content-Length: 504014
Content-Type: application/octet-stream
Content-MD5: /i5aFVWYlPqZjHvU+gxcbw==
Last-Modified: Wed, 13 Dec 2017 20:22:02 GMT
Accept-Ranges: bytes
ETag: "0x8D542672BB913FD"
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
Date: Thu, 11 Jan 2018 13:44:14 GMT
我不知道我在这里缺少什么,但最重要的是,如何使这段代码在生产服务器上运行?
被修改
澄清一些方面:
调用v_Blob.FetchAttributes()
时发生异常。
如果我拨打v_Blob.Exists()
,也会发生同样的异常。
我确定blob是Block Blob,两个调用(一个来自我的开发机器,另一个来自生产服务器)是同一个帐户和相同的Blob对象,具有完全相同的参数(连接字符串,容器字符串)和blob名称)。在我的开发机器上一切正常。
来自异常的堆栈跟踪:
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 604
at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.FetchAttributes(AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlob.cs:line 1619
at AzureDataMigration.Class.ConfereDocsMigrados.createBlockBlob(String p_Name, Int64 p_IdCompany, Int64 p_IdDocumentConfigType, StorGlobalHistoricalDocsEntities p_Model)
at AzureDataMigration.Class.ConfereDocsMigrados.Confere()