Reputation: 385
I am trying to call a dll file that accepts command line arguments through c# code.
when I tried directly from cmd window it works but if I try to call this from C# it is showing following error : "No application is associated with the specified file for this operation"
sample cmd command - C:\Users\user name\source\repos\addconsole\addconsole\bin\Debug\netcoreapp3.1>dotnet AddConsole.dll 1 2 3
static void Main(string[] args)
{
var proc1 = new ProcessStartInfo();
proc1.UseShellExecute = true;
proc1.WorkingDirectory = @"C:\Users\user name\source\repos\addconsole\addconsole\bin\Debug\netcoreapp3.1";
proc1.FileName = @"addconsole.dll";
proc1.Arguments = "1 2 3";
Process.Start(proc1);
}
Need help on this.please note there is no exe file this application that needs to be called has a dll file which has main function that executes the operation.
Upvotes: 0
Views: 2030
Reputation: 6103
You actually need to call dotnet.exe
and provide the relevant arguments. So set the FileName to dotnet and the rest as arguments.
var proc1 = new ProcessStartInfo();
proc1.UseShellExecute = true;
proc1.WorkingDirectory = @"C:\Users\user name\source\repos\addconsole\addconsole\bin\Debug\netcoreapp3.1";
proc1.Arguments = "\"addconsole.dll\" 1 2 3";
proc1.FileName = "dotnet.exe";
Process.Start(proc1);
Upvotes: 2