naffie
naffie

Reputation: 729

await InsertAsync error in Azure Mobile Service TableController

My code was working fine but right now I get an error on all my TableControllers when awaiting the InsertAsync function. This is the code:

 // POST tables/Account
    public async Task<IHttpActionResult> PostAccount(Account item)
    {
        Account current = await InsertAsync(item);
        return CreatedAtRoute("Tables", new { id = current.Id }, current);
    }

The error says: Cannot await System.Threading.Tasks.Task<sampleAppService.DataObjects.Account> expression.

I have no idea what's causing this. Any help?

EDIT

The signature of the InsertAsync function

protected virtual Task<TData> InsertAsync (TData item);

Upvotes: 0

Views: 236

Answers (2)

Rupa Mistry
Rupa Mistry

Reputation: 383

Assuming that your InsertAsync() is performing some async operation which is getting awaited inside, your InsertAsync() method signature must be modified to include the async word:

protected virtual async Task<TData> InsertAsync (TData item)
{
    await dbContext.InsertAsync(item);
}

Upvotes: 0

naffie
naffie

Reputation: 729

Based on Sebi's suggestion above, all I had to do was change the .Net Framework target from 4.5 to 4.5.1 in my case. That resolved the errors for me.

Upvotes: 1

Related Questions