Search code examples
asp.netentity-framework.net-core-rc2

Running Dotnet EF migrations add ... generates FileNotFoundException when run


Error generated is as follows.

System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified.
File name: 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'
   at Microsoft.DotNet.ProjectModel.ProjectReader.ReadProject(Stream stream, String projectName, String projectPath, ProjectReaderSettings settings)
   at Microsoft.DotNet.ProjectModel.ProjectReader.GetProject(String projectPath, ProjectReaderSettings settings)
   at Microsoft.EntityFrameworkCore.Tools.DispatchCommand.<>c__DisplayClass2_0.<Create>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified.

This error occurs for any DOTNET EF command (even --help)

we have multiple machines that this does work on but 2 of the machines are seeing the above error, and it is very frustrating?

I have even tried to install just the ProjectModel component from Github with no success

Any help appreciated on how to get over this issue


Solution

  • I tried the suggested of uninstalling and deleting all of the DNX and DOTNET directories to no avail.

    Then i did some more searching and found the answer. I had to change my Tools - entityframework configuration to the following

    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net451+win8"
    
    },
    

    Then I had to clear the caches for the Entity Framework as per this article link https://github.com/aspnet/EntityFramework/issues/5458#issuecomment-221912806

    Then I needed to remove the Reference for Microsoft.EntityFrameworkCore.SqlServer from the project and let VS fix up the reference itself by reloading

    After this a Build sorted out the issue and i could again run dotnet ef commands