async await Task null reference exception

折月煮酒 提交于 2019-12-02 08:27:08

I just had this issue and would like to suggest this as the answer.

In your web.config make sure you have the following:

  <system.Web>
      <httpRuntime targetFramework="4.5" />
  </system.Web>

and

<appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />     
</appSettings>

See more info here:

https://blogs.msdn.microsoft.com/webdev/2012/11/19/all-about-httpruntime-targetframework/

It seems to just crash randomly if you don't do this. I am a big fan of backwards compatibility but not when it just crashes if you don't opt in to the new way.

(Suggested in comment from Stephen Cleary)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!