Joshcodes Joshcodes - 1 month ago 15
C# Question

Azure Storage Tables ExecuteAsync Hangs on Retrieve TableOperation

Given two C# applications (Web, Test, Console, or otherwise) that both include a library, when run, one application hangs and the other application runs flawlessly.

The offending code is a Retrieve

TableOperation
to Azure Storage Tables shown here:

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);
...
}


All of the parameters used to setup the connection are the same in both applications and the code is running from the same machine. Writing to Azure Storage Tables works in both applications.

The question is, why does this work in one application and not the other?

Answer Source

The cause of the problem is a failure to load Newtonsoft.Json. The failure occurs if the library references a version of Newtonsoft that is not in the range permitted by the dependent assembly bindings. Here is an example:

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.

Updating your config file for the project that's not working will allow it to find the version of Newtonsoft.Json that gets included from the referenced library.