Ho aggiunto il riferimento principale a entityframework nel mio progetto webapi core completo, ma provoca un errore. Ho registrato il contesto db in Startup.cs come mostrato nella schermata qui sotto. Quando provo a eseguirlo (usando dotnet run) il codice genera un errore! L'errore è mostrato sotto, c'è qualcosa che sto facendo male?
Molte grazie, qualsiasi aiuto apprezzato.
Linea di rottura
services.AddDbContext<DbContext1>(options => options.UseSqlServer(Configuration.GetConnectionString("DbContext1")));
Errore
>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
File del pacchetto (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"
Aggiornare
Ho creato il progetto in questo modo
Se è ancora in corso, ho appena aggiornato Microsoft.Extensions.Logging
in NuGet Manager, quindi mi ha aiutato.