【问题标题】:EntityFramework Core reference causes compiler errorEntityFramework Core 引用导致编译器错误
【发布时间】:2017-02-18 18:27:21
【问题描述】:

我已将实体框架核心引用添加到我的完整框架核心 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

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

更新

我是这样创建项目的

【问题讨论】:

  • 假设您已经完成了清理和重建?
  • 是的,我有(在 Visual Studio 中)
  • 你的包文件是什么样的?
  • 我已经用 project.json 内容更新了我的问题,希望对您有所帮助
  • 你还有其他主项目依赖的项目吗?如果是这样,请检查他们的 project.json 以获取对 1.0.0 版本的旧引用。

标签: c# entity-framework-core asp.net-core-webapi


【解决方案1】:

如果它仍然发生,我刚刚在 NuGet 管理器中升级了 Microsoft.Extensions.Logging,所以它帮助了我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多