EntityFramework Core引用導致編譯器錯誤

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

我已將entityframework核心引用添加到我的完整框架核心webapi項目中,但它會導致錯誤。我在Startup.cs中註冊了db上下文,如下面的屏幕截圖所示。當我嘗試運行它(使用dotnet run)時,代碼會拋出錯誤!錯誤如下所示,有什麼我做錯了嗎?

非常感謝,任何幫助表示讚賞。

突破

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

錯誤

>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文件

包文件(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"

更新

我這樣創建了這個項目

在此處輸入圖像描述

在此處輸入圖像描述

熱門答案

如果它仍在發生,我只是在NuGet管理器中升級了Microsoft.Extensions.Logging ,所以它幫助了我。



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow