[英]C# Azure - Specified Resource not found after moving from Microsoft.Azure.Cosmos.Table to Azure.Data.Tables
I have an Azure storage account with a table that we are trying to access using C# in a function app.我有一个 Azure 存储帐户,其中有一个表,我们正尝试在 function 应用程序中使用 C# 访问该表。 I migrated over from the deprecated Microsoft.Azure.Cosmos.Table library to Azure.Data.Tables.
我从已弃用的 Microsoft.Azure.Cosmos.Table 库迁移到 Azure.Data.Tables。
I get an error when trying to query the table for an entity.尝试在表中查询实体时出现错误。
{
"The specified resource does not exist.
RequestId:8612b003-0002-0071-64b2-054424000000
Time:2022-12-01T18:27:02.5504487ZrnStatus: 404 (Not Found)
ErrorCode: ResourceNotFound
Content:
{
"odata.error":
{
"code":"ResourceNotFound",
"message":
{
"lang":"en-US",
"value":"The specified resource does not exist.
RequestId:8612b003-0002-0071-64b2-054424000000
Time:2022-12-01T18:27:02.5504487Z"
}
}
}
rnrnHeaders:rnCache-Control: no-cacher
Transfer-Encoding: chunked
Server: Windows-Azure-Table/1.0,
Microsoft-HTTPAPI/2.0
x-ms-request-id: 8612b003-0002-0071-64b2-054424000000
x-ms-client-request-id: c1668171-b91f-4eba-b2d1-1fef1120595a
x-ms-version: REDACTED
X-Content-Type-Options: REDACTED
Date: Thu, 01 Dec 2022 18:27:02 GMT
Content-Type: application/json;
odata=minimalmetadata;
streaming=true;
charset=utf-8rn"
}
Old previous working code旧的以前的工作代码
var primaryCloudStorageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("EntityRegistryStorageAccountConnectionString"));
var tableClient = primaryCloudStorageAccount.CreateCloudTableClient();
_registry = tableClient.GetTableReference("EntityRegistry");
Code with new libary that is not working使用无法正常工作的新库的代码
private readonly TableClient _registry;
_registry = new TableClient(Environment.GetEnvironmentVariable("EntityRegistryStorageAccountConnectionString"), "EntityRegistry");
Also tried this也试过这个
var tableClient = new TableServiceClient(Environment.GetEnvironmentVariable("EntityRegistryStorageAccountConnectionString"));
_registry = tableClient.GetTableClient("EntityRegistry");
Error is thrown in this code此代码中抛出错误
var registryRecord = await _registry.GetEntityAsync<TableEntity>(entityType.ToString(), registryId);
This also returns a 404 error这也会返回 404 错误
var registryRecord = await _registry.GetEntityIfExistsAsync<TableEntity>(entityType.ToString(), registryId);
I know the table exists and it seems to be authenticating me, I can see the URL that is being set on the TableClient and it matched what I see in Azure. I also use the connection string from Azure that has the account and key.我知道该表存在并且它似乎正在对我进行身份验证,我可以看到在 TableClient 上设置的 URL,它与我在 Azure 中看到的相匹配。我还使用来自 Azure 的连接字符串,其中包含帐户和密钥。
What could be going on with this?这可能是怎么回事?
Important note!重要的提示!
In the past library, the GetEntity call would be okay with returning null if the record does not exist.在过去的库中,如果记录不存在,GetEntity 调用可以返回 null。 In this case, you need to call GetEntityIFExistsAsync and parse the value returned, it won't just return null like it did previously if the value does not exist.
在这种情况下,您需要调用 GetEntityIFExistsAsync 并解析返回的值,如果该值不存在,它不会像以前那样只返回 null。
var registryRecord = await _registry.GetEntityIfExistsAsync<TableEntity>(entityType.ToString(), registryId);
if (registryRecord.HasValue)
return registryRecord.Value;
else
return null;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.