Call to ReplaceDocumentAsync method fails to return
<p>I am not getting a response from the async DocumentDB ReplaceDocument method when running in a web context (IIS). When running locally, it works just fine. From my research this is appears something to do with a conflicting deadlock with a UI thread?</p>

<p>I am getting good responses from other async calls like so:</p>

<pre><code>this.Client.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(this.DatabaseName)).Result;
// and
this.Client.CreateDatabaseAsync(new Database { Id = this.DatabaseName }).Result;
// etc
</code></pre>

<p>I'm not using await as in an IIS context is seems to never respond. I'm not sure why, so I removed all the async awaits, and started using <code>.Result</code> and everything works now except the below method.</p>

<p>According to this question <a href="https://stackoverflow.com/questions/11316438/call-to-await-getfileasync-never-returns-and-app-hangs-in-winrt-app">Call to await GetFileAsync() never returns and app hangs in WinRT app</a> . I have set up the <code>ConfigureAwait(false)</code> and am calling <code>GetResult()</code>. But the method doesn't return, and the thread eventually closes without return.</p>

<pre><code>var task = this.Client.ReplaceDocumentAsync(this.GetDocumentLink(d.id), d, options);
var configuredTask = task.ConfigureAwait(false);
var awaiter = configuredTask.GetAwaiter();
var result = awaiter.GetResult();
</code></pre>

<p>I have also tried the following permutations:</p>

<pre><code>// in a spereate async method
await this.Client.ReplaceDocumentAsync(this.GetDocumentLink(d.id), d, options);
await this.Client.ReplaceDocumentAsync(this.GetDocumentLink(d.id), d, options).ConfigureAwait(false);

// as well as trying a call back
.GetAwaiter().OnCompleted(() =&gt; /* never gets here either */);
</code></pre>

<p><strong>EDIT</strong></p>

<p>I have this in my <code>Web.config</code> (via :<a href="https://stackoverflow.com/questions/9562836/whats-the-meaning-of-usetaskfriendlysynchronizationcontext">What&#39;s the meaning of &quot;UseTaskFriendlySynchronizationContext&quot;?</a>)</p>

<pre><code>&lt;appSettings&gt;
    &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
&lt;/appSettings&gt;

and

&lt;system.web&gt;
    &lt;compilation debug="true" targetFramework="4.6.1" /&gt;
    &lt;httpRuntime targetFramework="4.5" /&gt;
&lt;/system.web&gt;
</code></pre>