我已将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
包文件(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"
更新
我创建了这样的项目
答案 0 :(得分:0)
如果它仍在发生,我刚刚在NuGet管理器中升级Microsoft.Extensions.Logging
,所以它帮助了我。