Efcore: erro command: dotnet ef migrations add Initial

Created on 9 Apr 2016  路  15Comments  路  Source: dotnet/efcore

Hello dear friends, I am facing a small problem of dependence with dotnet EF migrations.
There is already a solution for this bug / Feedback
I am using the RC2 version dotnet cli
My project.json is:

"dependencies": {
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-_",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-_",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-_",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-_",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-_",
"Microsoft.AspNetCore.Mvc": "1.0.0-_",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-_",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-_",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-_",
"Microsoft.AspNetCore.Server.WebListener": "0.1.0-_",
"Microsoft.AspNetCore.Session": "1.0.0-_",
"Microsoft.EntityFrameworkCore.Commands": { "version": "1.0.0-_", "type": "build" },
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0-_",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-_",
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-_",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-_",
"Microsoft.Extensions.Configuration.Json": "1.0.0-_",
"Microsoft.Extensions.Logging.Console": "1.0.0-_",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0-_",
"Microsoft.NETCore.Platforms": "1.0.1-_",
"System.IO": "4.1.0-_",
"System.Runtime": "4.1.0-_"
}

ERRO:

System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at ERPJamsoft.Startup..ctor(IApplicationEnvironment AppEnv, IRuntimeEnvironment RunEnv) in R:\Ralms DevNET\Sistemas\ERPJamsoftsrc\ERPJamsoft\Startup.cs:line 22
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.EntityFrameworkCore.Design.Internal.StartupInvoker.Invoke(Type type, String[] methodNames, IServiceCollection services)
at Microsoft.EntityFrameworkCore.Design.Internal.StartupInvoker.ConfigureServices()
at Microsoft.EntityFrameworkCore.Design.DbContextOperations..ctor(ILoggerProvider loggerProvider, Assembly assembly, Assembly startupAssembly, String environment, String startupProjectDir)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations..ctor(AssemblyLoader assemblyLoader, ILoggerProvider loggerProvider, Assembly assembly, Assembly startupAssembly, String environment, String projectDir, String startupProjectDir, String rootNamespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<>c__DisplayClass4_0.<.ctor>b__5()
at Microsoft.EntityFrameworkCore.Internal.LazyRef1.get_Value() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_01.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

type-investigation

Most helpful comment

I'm seeing the same thing, except in my case it's looking for version 7.0.0.0.

All 15 comments

I'm seeing the same thing, except in my case it's looking for version 7.0.0.0.

I'm also getting this error (for v7).

@natemcmaster thoughts on this? Is this a symptom of known issues with dotnet ef or is it something new?

@ralmsdeveloper can you post your full project.json? I didn't see your "tools" section in the original issue.

Also, please be aware dotnet-ef is not fully ready. There is ongoing work for RC2. See #5002 and https://github.com/aspnet/EntityFramework/issues/4577

Similar error.

System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
File name: 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at Microsoft.DotNet.ProjectModel.ProjectReader.ReadProject(Stream stream, String projectName, String projectPath, ICollection`1 diagnostics, ProjectReaderSettings settings)
   at Microsoft.DotNet.ProjectModel.ProjectReader.GetProject(String projectPath, ICollection`1 diagnostics, ProjectReaderSettings settings)
   at Microsoft.EntityFrameworkCore.Commands.ReflectionOperationExecutor.GetCompatibleProjectContext(String projectPath)
   at Microsoft.EntityFrameworkCore.Commands.ReflectionOperationExecutor..ctor(String startupProject, String environment)
   at Microsoft.EntityFrameworkCore.Commands.MigrationsAddCommand.Execute(String name, String outputDir, String context, String startupProject, String environment, Action`1 reporter)
   at Microsoft.EntityFrameworkCore.Commands.MigrationsAddCommand.<>c__DisplayClass0_0.<Configure>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Commands.Program.Main(String[] args)
Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

It also happens with dotnet watch. Where are these tools looking for Newtonsoft.Json?

Part of the issue here is that dotnet-ef and dotnet-watch could be your imports. For the moment, specifying tools also requires listing "imports".

"tools": {
    "dotnet-ef": { 
       "version": "1.0.0-*",
       "imports": [ "dnxcore50", "portable-net452+win81" ]
    }
}

cref https://github.com/dotnet/cli/issues/1970

I already have that in my project.json in this PR

Sorry - commented on the wrong github notification.

@natemcmaster There seems to still be problems on the latest aspnetcidev feed with dotnet-ef v1.0.0-rc3-20565, even after https://github.com/aspnet/EntityFramework/pull/5002.

Specifically, I get:

Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

when I try to build a configuration in Startup.cs:

public Startup(IApplicationEnvironment appEnv)
        {
            Configuration = new ConfigurationBuilder()
                .SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .Build();
        }

The project.json file looks as follows:

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.EntityFrameworkCore.Commands": "1.0.0-*",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-*",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-*"
  },

  "frameworks": {
    "netstandard1.5": {
      "imports": "portable-net45+win8+wp8"
    }
  },

  "tools": {
    "dotnet-ef": {
      "version": "1.0.0-*",
      "imports": "portable-net45+win8+wp8"
    }
  }
}

@rmja we are still tracking down issues here. Can you help us out? What if you replace your portable imports with a different profile? Try using "portable-net452+win81" instead.

@natemcmaster I will be happy to. Let me know what I can do from my side. I have changed the includes in both the framework and tools sections, but that does not make any difference.

From the recipe in https://github.com/aspnet/EntityFramework/issues/3925 I followed these steps:
Deleted all content in the .nuget/packages folder, followed by dotnet restore using the aspnetcidev feed, however dotnet ef migrations add Whatever still fails with the same exception.

Clearing up milestone so that we can review in triage. This might be RC2 (but perhaps is a dupe if we are tracking it in the commands issue).

This issue is caused by incomplete isolation provided by System.Runtime.Loader.AssemblyLoadContext. We built dotnet-ef around this isolation model, but have discovered it doesn't provide enough isolation for scenarios such as this. See https://github.com/dotnet/cli/issues/2514

Closing as we will track this as part of https://github.com/aspnet/EntityFramework/issues/3925

Do we have any update on this one?

Was this page helpful?
0 / 5 - 0 ratings