Last post Mar 16, 2012 04:09 AM by levib
Mar 08, 2012 01:04 PM|MisinformedDNA|LINK
I have a search action that has two paths, a synchronous path, that just returns a simple view, and a asynchronous path, that does the search asynchronously and then returns a view. Both are GET requests, so they are part of the same action.
The problem is that when I access the action "localhost:XXXX/Home/Search", the page just infinitely loads. Using Fiddler, I can see that the request never returns. I've debugged it and it makes it to the last line of code, but, again, the request doesn't
I've simplified the repro to the following:
public async Task<ActionResult> Search()
VS11 warns me that the code will be run synchronously without an await, which is fine, but the request doesn't complete.
Should this work? Or do I need to something else here?
Mar 15, 2012 03:39 AM|Eilon|LINK
This was a bug in the MVC 4 Beta that we have fixed for the next release. I'm following up to see if there's a workaround you can use in the meantime (aside from just not using async).
Mar 16, 2012 04:09 AM|levib|LINK
To work around this issue for the Beta, do two things. First, add the following to your ~/Web.config if it is not already there:
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
Second, add this as the first line within your Task-returning action method:
The second part (the 'await Task.Yield();') will not be necessary once this bug is fixed post-Beta.
Hope this helps!