c# - Azure 存储表 ExecuteAsync 在 Retrieve TableOperation 上挂起

标签 c# .net azure freeze azure-table-storage

给定两个都包含库的 C# 应用程序(Web、测试、控制台或其他),运行时,一个应用程序会挂起,而另一个应用程序会完美运行。

违规代码是对 Azure 存储表的 Retrieve TableOperation,如下所示:

private async Task<bool> FindByIdAsync<TData>(string rowKey)
    where TData : class, ITableEntity
{
    var table = GetTable<TData>();
    var operation = TableOperation.Retrieve<TData>(
        rowKey.GeneratePartitionKey(), rowKey);
    var result = await table.ExecuteAsync(operation);
    ...
}

用于设置连接的所有参数在两个应用程序中都是相同的,并且代码在同一台计算机上运行。写入 Azure 存储表在这两个应用程序中均有效。

问题是,为什么这在一个应用程序中有效,而在另一个应用程序中无效?

最佳答案

问题的原因是加载Newtonsoft.Json失败。如果库引用的 Newtonsoft 版本不在依赖程序集绑定(bind)允许的范围内,则会发生故障。这是一个例子:

app.config / web.config of offending application

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
       <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
       <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
    </dependentAssembly>
</assemblyBinding>

app.config / web.config of working application

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
       <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
       <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
    </dependentAssembly>
</assemblyBinding>

Note the version range increased to support 7.0.0.0.

更新不工作的项目的配置文件将允许它找到从引用的库中包含的 Newtonsoft.Json 版本。

关于c# - Azure 存储表 ExecuteAsync 在 Retrieve TableOperation 上挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33398749/

相关文章:

.net - 为什么探查器无法附加?

.net - 从本地站点登录到 Azure

webapp 上的 Azure keyvault 访问策略而不是应用程序服务主体

C# - BitArray 到十六进制

c# - 如何获取IP地址?

c# - 使用 foreach 迭代 ListCollectionView

azure - 将 SSL 证书绑定(bind)到 Azure 托管 API 中的特定终结点

c# - 如何重写办公自动化代码

c# - 单元测试 .net Web Api。设置查询字符串值

c# - 为什么我必须创建 `IEnumerable<T>` 的具体实现才能修改其成员?