locked
about LegacyAspNetSynchronizationContext and async RRS feed

  • Question

  • User-507696518 posted
    public async Task<ActionResult> TestModelBinder(CancellationToken cancellationToken)
            {
               
                await Task.Delay(1);
                var x = System.Web.HttpContext.Current;
                return Content("test");
    
            }

    this is one of action in my controller,and when the SynchronizationContext.Current type is

    LegacyAspNetSynchronizationContext,the variable x will be null!but when

    the SynchronizationContext.Current type is AspNetSynchronizationContext,the variable x will

    not be null. I want to know what is the cause of it.thanks.

    Thursday, December 21, 2017 2:51 AM

Answers

  • User-707554951 posted

    Hi huangke1993,

    The legacy type (LegacyAspNetSynchronizationContext) in your call stack indicates that your web.config settings are incorrect. Set targetFramework to 4.5 or higher.

    async cause undefined behavior on earlier versions of ASP.NET. 

    Related thread:

    https://stackoverflow.com/a/38119187

    Best regards 

    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 22, 2017 2:05 AM

All replies

  • User-707554951 posted

    Hi huangke1993,

    The legacy type (LegacyAspNetSynchronizationContext) in your call stack indicates that your web.config settings are incorrect. Set targetFramework to 4.5 or higher.

    async cause undefined behavior on earlier versions of ASP.NET. 

    Related thread:

    https://stackoverflow.com/a/38119187

    Best regards 

    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 22, 2017 2:05 AM
  • User-507696518 posted

    thank you

    Friday, December 22, 2017 2:39 AM