Joshcodes
Joshcodes

Reputation: 8911

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?

Upvotes: 2

Views: 1127

Answers (2)

Jnr
Jnr

Reputation: 1684

Thanks. I had the same problem but with a background app. The app uses Json as the config file but there was no Newtonsfot.Json entry. I added the entry with the latest compatible version available.

"Newtonsoft.Json": "9.0.1"

Upvotes: 0

Joshcodes
Joshcodes

Reputation: 8911

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.

Upvotes: 3

Related Questions