1

Possible Duplicate:
“Asynchronous operations are not allowed in this context”

So, I've got a master page that calls the following method:

public static bool GetAdsEnabled()
{
    return SomeAsyncMethodThatReturnsTaskOfBool().Result;
}

as follows:

<%if(AdsHelper.GetAdsEnabled())
  { //blah
  }%>

however, it seems that perhaps the Scheduler has been messed with such that even though this code should execute synchronously, it actually throws the following error:

InvalidOperationException: Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.

This seems like a case of mistaken identity. How can I use an async method synchronously in an asp.net mvc context?

Community
  • 1
  • 1
spender
  • 117,338
  • 33
  • 229
  • 351

0 Answers0