2020-11-27

cannot convert system.threading.tasks.task to system.collections.generic.list

Yes, this is (most likely) a duplicate, but the reason I am making this duplicate is because I have tried the other answers I have found on StackOverflow (and other websites) and none have worked for me. So I assume either I am doing something wrong, or my problem isn't what is being presented to me.

My error is: cannot convert system.threading.tasks.task to system.collections.generic.list

I have read that the problem could be that my method isn't async and that the content I am returning should have await, but unfortunately this didn't do the trick either. I have tried a couple of other solutions, such as making an async method to call from my constructor etc, but unfortunately... No success.

This is what I have right now (do note: I took out the async and await keywords again, since they didn't help):

    public Task<List<ABut>> GetItemsAsync()
    {
        return Database.Table<ABut>().ToListAsync();
    }

My property which I instantiate:

//THIS IS IN ANOTHER CLASS, WHICH I USE TO CONTROL MY DATABASE OBJECT WITH
public List<ABut> AButs{ get; set; }

How I call this method from within the constructor (The property AButs is place in the same class as the constructor) constructor:

//THIS IS IN ANOTHER CLASS, WHICH I USE TO CONTROL MY DATABASE OBJECT WITH
//The property Connection is assigned a new database connection of sqlite
public SecondClassConstructor()
{
    AButs = Connection.GetItemsAsync(); // causes the error
}

I have tried a lot and read about the problem itself, the async and await keywords and how they work etc, but unfortunately no success so far.

The only thing that prevents the error, but breaks the application when I try to run it:

AButs = (List<ABut>)(IEnumerable<ABut>)Connection.GetItemsAsync();

The desired behavior what I'm looking for:

To be able to retrieve it as a List and work with it



from Recent Questions - Stack Overflow https://ift.tt/33CgUwv
https://ift.tt/eA8V8J

No comments:

Post a Comment