1
votes

I'm getting this error when I try to convert Task<decimal> to decimal:

Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Here is my method:

public async Task<decimal> GetTotalProposalAmount()
{
    using (DataContext db = new DataContext())
    {
        var total = db.Database.SqlQuery<decimal>("Get_ProposalTotal", null);
        return await total.FirstAsync();
    }
}

I'm calling it here in the controller:

public async Task<ActionResult> Index(int? page, string search)
{

   model.Proposaltotal = Convert.ToDecimal(GetTotalProposalAmount());
    return View(model);
}
1
Read the Warnings: Index() is not awaiting anything. - Henk Holterman
your error has nothing to do with Task and Async... your just using it incorrectly but that's not why your getting an error. - Seabizkit

1 Answers

10
votes

You simply have to await the task:

model.Proposaltotal = await GetTotalProposalAmount();

This has nothing to do with your build error though, just add the reference it asks for.