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

340 views Asked by At

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

2

There are 2 answers

0
Grant Nilsson On BEST ANSWER

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

1
Gary Holland On

I had this problem (along with other similar errors running other dotnet commands. For me it was due to having older RC1 and SDK installations. I removed everything from add/remove programs, along with removing the dotnet and DNX directories in c:\program files. Then I reinstalled and it started working.