Exception Instantiating DBContext in EF Core

.net-core asp.net entity-framework-core


Loaded EntityFrameworkCore v2.1.0 , EntityFrameworkCore.Tools, EntityFrameworkCore.SQLServer and Extensions.DependencyInjection.Abstractions using NuGet.

Everything builds. Web App runs to the point of instantiating DBContext, then errors:

Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.

at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options) at Microsoft.EntityFrameworkCore.DbContext..ctor() at Repository.RepoContext..ctor() at Business.AccountBLL.GetAccountListing() at ServiceFacade.AccountService.GetAccountListing() at AnnualMileageReport.FillAccounts() in C:\Users\v\source\AnnualMileageReport.aspx.vb:line 23 at AnnualMileageReport.Page_Load(Object sender, EventArgs e) in C:\Users\v\source\AnnualMileageReport.aspx.vb:line 17 at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

The file is present along with EF Core in the referenced path.

I have reviewed various SO answers to related questions but the modifications recommended have not fixed my problem. Versioning is correct. modifications to the proj file had no effect. I have removed and re-installed EF Core and dependencies with no success. I have removed bin and obj folders, also no success.

I've been beating on this for hours. Please help!

5/23/2018 8:24:29 PM

Accepted Answer

This appears to be caused by missing binding redirects that are needed when using .NET Standard assemblies on certain versions of .NET Framework.

For libraries and executables, MSBuild tooling can autogenerate these. But for classic ASP.NET projects or web sites using web.config, this needs to be done by acting on an error message inside Visual Studio.

Generate binding redirects for web.config

5/24/2018 2:31:58 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow