Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "dotnet ef migrations add" throw a Win32Exception?

I have a dotnet core v3.1 project with an entity framework DbContext. when I try to run:

dotnet ef migrations add someMigrationName

this Exception will be thrown:

System.ComponentModel.Win32Exception (2): No such file or directory
   at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Microsoft.EntityFrameworkCore.Tools.Exe.Run(String executable, IReadOnlyList`1 args, String workingDirectory, Boolean interceptOutput)
   at Microsoft.EntityFrameworkCore.Tools.Project.FromFile(String file, String buildExtensionsDir, String framework, String configuration, String runtime)
   at Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute(String[] _)
   at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
No such file or directory

My development environment is a Linux elementary os (Ubuntu 18.04.4 LTS) and rider IDE.

It may be irrelevant but when I try to debug my xunit tests it returns this warning and cannot start execution.

All of these commands work properly and show all options:

  1. dotnet
  2. dotnet ef
  3. dotnet ef migrations

but when I use these options Exception raised:

  • dotnet ef migrations add
  • dotnet ef migrations list

Also, I run my command with verbose option and this is the output:

Using project '/media/navid/9bf0167c-d789-4e06-9e23-4023ec551745/Stuff/Work/SabaCell/venus/Venus.CustomerProfileManagement/Venus.CustomerProfileManagement.csproj'.
Using startup project '/media/navid/9bf0167c-d789-4e06-9e23-4023ec551745/Stuff/Work/SabaCell/venus/Venus.CustomerProfileManagement/Venus.CustomerProfileManagement.csproj'.
Writing '/media/navid/9bf0167c-d789-4e06-9e23-4023ec551745/Stuff/Work/SabaCell/venus/Venus.CustomerProfileManagement/obj/Venus.CustomerProfileManagement.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/tmp/tmpUud0Xf.tmp /verbosity:quiet /nologo /media/navid/9bf0167c-d789-4e06-9e23-4023ec551745/Stuff/Work/SabaCell/venus/Venus.CustomerProfileManagement/Venus.CustomerProfileManagement.csproj
System.ComponentModel.Win32Exception (2): No such file or directory
   at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Microsoft.EntityFrameworkCore.Tools.Exe.Run(String executable, IReadOnlyList`1 args, String workingDirectory, Boolean interceptOutput)
   at Microsoft.EntityFrameworkCore.Tools.Project.FromFile(String file, String buildExtensionsDir, String framework, String configuration, String runtime)
   at Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute(String[] _)
   at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
No such file or directory

this is the result of running dotnet --info in my environment:

.NET Core SDK (reflecting any global.json):
 Version:   3.1.405
 Commit:    3fae16e62e

Runtime Environment:
 OS Name:     elementary
 OS Version:  5.1.7
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.405/

Host (useful for support):
  Version: 3.1.11
  Commit:  f5eceb8105

.NET Core SDKs installed:
  3.1.405 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.1.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.11 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
like image 599
Navid_pdp11 Avatar asked Feb 03 '21 07:02

Navid_pdp11


People also ask

How do EF migrations work?

The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database.

How does EF core apply migrations?

Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.

How do you deploy EF migrations?

Right click your web project, click publish, use web deploy, go to your databases, target your new database, ensure Execute Code First Migrations is checked (this will run all the migrations you've done for your localdb on your new database).


3 Answers

This helped me,

I deleted dotnet symlink in /usr/local/bin/ (macOS)

like image 81
Bjorn Know Avatar answered Oct 07 '22 17:10

Bjorn Know


It didn't work for me removing the symlink. I had to reinstall the dotnet-ef tool:

dotnet new tool-manifest

dotnet tool install dotnet-ef

That fixed the issue :)

like image 44
Cfrim Avatar answered Oct 07 '22 18:10

Cfrim


I was able to solve this issue with @bjorn answer. there was a symlink in my /usr/local/bin pointing to /snap/..., back when I tried to install .net sdk with snap, which was not successful, so I tried a different approach. Just complementing @bjorn answer, this is what I did :

Check if you have a symlink :

ls -l /usr/local/bin/

It will look something like this :

lrwxrwxrwx 1 root root       54 jul 22 09:46 dotnet -> /snap/...

Then remove it :

sudo rm /usr/local/bin/dotnet
like image 4
PedroMiotti Avatar answered Oct 07 '22 18:10

PedroMiotti