This Code is running fine on my local machine
public async Task<ActionResult> teststuff()
{
using (var client = new HttpClient())
{
var twitter = await client.GetStringAsync("http://www.twitter.com");
Response.Write(twitter);
}
return View();
}
However when I upload to the server I Get the error response
Server Error in '/' Application.
The asynchronous action method 'teststuff' returns a Task, which cannot be executed synchronously. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The asynchronous action method 'teststuff' returns a Task, which cannot be executed synchronously.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The asynchronous action method 'teststuff' returns a Task, which cannot be executed synchronously.]
System.Web.Mvc.Async.TaskAsyncActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +125
2 parameters) +39
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
System.Web.Mvc.<>c__DisplayClass13.b__10() +120 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +637
1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +307
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +688
NotFoundMvc.ActionInvokerWrapper.InvokeActionWith404Catch(ControllerContext controllerContext, String actionName) +54
NotFoundMvc.ActionInvokerWrapper.InvokeAction(ControllerContext controllerContext, String actionName) +19
System.Web.Mvc.<>c__DisplayClass1d.b__19() +40
System.Web.Mvc.Async.<>c__DisplayClass1.b__0() +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15
System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288-------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
There is something missing on my server but just can't find out what it is any help would be appreciated.
I have tried re-installing .net framework 4.5 on the server but that had no effect. However I did notice on the sever it has both the
Microsoft .NET Framework 4 Multi-Targeting Pack and Microsoft .NET Framework 4.5 Multi-Targeting Pack
Not sure if I should remove the 4 one or not?
Thanks
Well it was odd I just deleted all the files in the website then re published the site and it all work fine.
I think this may have happen because I recently upgraded the site from a MVC3 site to MVC4 and there may have been an odd DLL left from the MVC3 site in the Directory.
Thanks Stephen for you suggestion it gave me the idea of wiping the site clean and re upping it