Error CS1061 \'Task>\' does not contain a definition for \'FirstOrDefault\' and no extension method \'FirstOrDefault\' accepting a first argument of type
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.
You are missing an await
in front of UserManager.GetClaimsAsync()
:
var currentClaims = await UserManager.GetClaimsAsync(...);