ESD
ESD

Reputation: 545

Launching debug mode application from c#

I am currently working on a c++ project and I made a C# wpf launcher to go with it.

These will work :

However starting the file.exe in the debug folder from c# code result in the c++ program crashing on launch. I even tried running the same command line in c# that worked by typing it and it result in a crash.

After attaching the debugger to the c++ process the cause of the crash seems to be missing assets (some shader code). However the assets folder is in the debug directory and as I said the program runs by clicking on it.

I have tried in c# :

What could cause this?

Upvotes: 0

Views: 411

Answers (1)

ESD
ESD

Reputation: 545

As mentioned by Vikas the working directory needs to be set or it seems like windows won't allow the process to access files.

Here is the code that worked for me :

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(this.PathToExeTextBox.Text);
startInfo.FileName = this.PathToExeTextBox.Text;
Process.Start(startInfo);

Upvotes: 1

Related Questions