Task does not contain a definition for 'FirstOrDefault'

前端 未结 2 1731
清歌不尽
清歌不尽 2020-12-22 06:47

Error CS1061 \'Task>\' does not contain a definition for \'FirstOrDefault\' and no extension method \'FirstOrDefault\' accepting a first argument of type

相关标签:
2条回答
  • 2020-12-22 07:04

    Look closely at the error message. GetClaimsAsync returns type Task<IList<Claim>>, not type list. The Task type doesn't have a FirstOrDefault method. As other people have indicated, await GetClaimsAsync and it'll work.

    As a side note, do not use .Result here as that will deadlock in most environments. See this article for an explanation of why this will deadlock as well as this article on async/await best practices.

    0 讨论(0)
  • 2020-12-22 07:11

    You are missing an await in front of UserManager.GetClaimsAsync():

    var currentClaims = await UserManager.GetClaimsAsync(...);
    
    0 讨论(0)
提交回复
热议问题