给定两个都包含库的 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/