Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using Process.Start to run a .NET 6 dll

I want to start a process with some arguments out of a .NET 6 console application to run a dll that was also created in .NET 6.

When I try to cmd:
> dotnet myPath/myApp.dll testParam everything works fine

but when I try to use:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Process process = new Process();
        process.StartInfo.FileName = "dotnet myPath/myApp.dll";
        process.StartInfo.WorkingDirectory = "myPath";
        process.StartInfo.Arguments = "testParam";
        process.StartInfo.UseShellExecute = false;
        process.Start();

I’m getting the following exception

System.ComponentModel.Win32Exception: ‘An error occurred trying to start process ‘dotnet myPath/myApp.dll testParam’ with working directory ‘myPath’.

As I try to copy and paste the string out of the exception into cmd, it works just fine.

I tried to set the working directory, as explained here

>Solution :

Please see the documentation https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=net-6.0

var dllPath = Path.Combine("myPath", "myApp.dll");

using Process process = new Process();
process.StartInfo.FileName = "dotnet"; // Append ".exe" if on windows
process.StartInfo.Arguments = $"{dllPath} testParam";
process.StartInfo.UseShellExecute = false;
process.Start();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading