skip to Main Content

Currently I’m writing a TicketSystem in ASP.NET and have trouble with the Admin Panel.

I want read out the user roles and I’m getting the following error message:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: "’System.Threading.Tasks.Task<System.Collections.Generic.IList<string>>’ does not contain a definition for ‘ToList’"

Code to read the user role:

 public  List<String> getRols(dynamic user)
    {

        return _UserManager.GetRolesAsync(user).ToList();
       
    } 

Many Thanx for your Help

2

Answers


  1. You’re trying to access to add the ToList on a Task, which is something that doesn’t exist. You either have to await the method, or take the result from the async call.

    The best solution is the await solution, so it would be:

    public async Task<List<string>> getRols(dynamic user)
    {
        return await _UserManager.GetRolesAsync(user);
    } 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search