Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core Process.Start on Linux

Tags:

I am facing the following issue when running my .Net Core application on Linux.

Here is the exception:

System.ComponentModel.Win32Exception (0x80004005): Permission denied    at Interop.Sys.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Int32& lpChildPid, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd)    at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)    at System.Diagnostics.Process.Start()    at Ombi.Schedule.Jobs.Ombi.OmbiAutomaticUpdater.<Update>d__18.MoveNext() in C:\projects\requestplex\src\Ombi.Schedule\Jobs\Ombi\OmbiAutomaticUpdater.cs:line 218 

Here is the code:

var updaterFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),      "TempUpdate", $"Ombi.Updater");  var start = new ProcessStartInfo {     UseShellExecute = false,     CreateNoWindow = true,     FileName = updaterFile,     Arguments = GetArgs(settings), // This just gets some command line arguments for the app i am attempting to launch     WorkingDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TempUpdate"), };  using (var proc = new Process { StartInfo = start }) {     proc.Start(); } 

It seems that the exception is being thrown when we call .Start().

I am not sure why this is happening, the permissions on the file and folders have been set to 777.

like image 583
Jamie Rees Avatar asked Dec 13 '17 09:12

Jamie Rees


People also ask

Does process start work on Linux?

Not supported on Linux The following properties of ProcessStartInfo aren't supported on Linux and throw PlatformNotSupportedException : PasswordInClearText , Domain , LoadUserProfile , Password .

Can .NET Core application run on Linux?

The . NET Core runtime allows you to run applications on Linux that were made with . NET Core but didn't include the runtime. With the SDK you can run but also develop and build .


Video Answer


1 Answers

After years, I ran into same error and did not like approach of making .dll executable for this. Instead setting FileName to "dotnet" and passing dll path as first argument will do the trick.

var updaterFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),      "TempUpdate", $"Ombi.Updater");  var start = new ProcessStartInfo {     UseShellExecute = false,     CreateNoWindow = true,     FileName = "dotnet", // dotnet as executable     Arguments = updaterFile + " " +GetArgs(settings),  // first argument as dll filepath     WorkingDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TempUpdate"), };  using (var proc = new Process { StartInfo = start }) {     proc.Start(); } 
like image 71
Haldun Avatar answered Sep 28 '22 18:09

Haldun