EntityFramework Core reference causes compiler error

asp.net-core-webapi c# entity-framework-core

Question

I've added the entityframework core reference into my full framework core webapi project but it causes an error. I have registered the db context in Startup.cs as shown in the screen shot below. When I attempt to run it (using dotnet run) the code throws an error! The error is shown below, is there anything I'm doing wrong?

Many thanks, any help appreciated.

Breaking line

services.AddDbContext<DbContext1>(options => options.UseSqlServer(Configuration.GetConnectionString("DbContext1")));

Error

>dotnet run
Project something (.NETFramework,Version=v4.6) will be compiled because inputs were modified Compiling something for .NETFramework,Version=v4.6

Compilation succeeded.
0 Warning(s)
0 Error(s)

Time elapsed 00:00:01.4944030


Unhandled Exception: System.Reflection.TargetInvocationException:     Exception has been thrown by the target of an invocation. ---> 

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference (Exception from HRESULT: 0x80131040) at something.Startup.ConfigureServices(IServiceCollection services)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection exportServices) at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at something.Program.Main(String[] args) in C:\Projects\tms-sime\src\something\Program.cs:line 15

startup.cs file

Package file (project.json)

{
  "dependencies": {
  "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
  "Microsoft.AspNetCore.Mvc": "1.0.1",
  "Microsoft.AspNetCore.Routing": "1.0.1",
  "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
  "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
  "Microsoft.EntityFrameworkCore": "1.0.1",
  "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
  "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
  "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
  "Microsoft.Extensions.Configuration.Json": "1.0.0",
  "Microsoft.Extensions.Logging": "1.0.0",
  "Microsoft.Extensions.Logging.Console": "1.0.0",
  "Microsoft.Extensions.Logging.Debug": "1.0.0",
  "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"

Update

I created the project like so

enter image description here

enter image description here

1
0
10/10/2016 12:47:54 PM

Popular Answer

If it's still occurring, I just upgraded Microsoft.Extensions.Logging in the NuGet Manager, so it helped me.

0
1/13/2017 10:28:50 PM


Related Questions





Related

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