Prithiv
Prithiv

Reputation: 504

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in mscorlib.dll

I have an application with WF control hosted in WPF window and i'm proceesing some record and playback actions in my project. I get the below exception while performing play back.

The system cannot find the file specified

I have searched regarding this and seen some suggestions that we need to provide the full path of the file to process.I have tried this also, but still i'm getting this exception.

Please anyone let me know how to resolve this?

var instance = testclass.GetControlForTest();
WindowsFormsHost host = new WindowsFormsHost();
host.Child = instance;

var testwindow = new TestWindow(testdata, testclass, false, (MainWindow)Application.Current.MainWindow, true);
testwindow.testSurface.Children.Add(host);

testwindow.Show();
await Task.Delay(1000);
Process p = new Process();
var mainPath = Directory.GetCurrentDirectory();

do
{
    mainPath = Directory.GetParent(mainPath).FullName;
} while (Directory.GetParent(mainPath).Name != "WindowsForms_Testing");
var targetPath = mainPath + "\\exes\\" + "\\";
mainPath = Directory.GetParent(mainPath).FullName;
mainPath = mainPath + "\\TestStudio\\Syncfusion.TestVisualBase.WPF\\RecordAction\\RecordAction.WPF\\bin\\Debug\\RecordAction.WPF.exe";
p.StartInfo.FileName = mainPath.Replace("\\", "/");
p.StartInfo.Arguments = file; //("..//..//test.xml")
p.Start();

Thanks,

Upvotes: 1

Views: 2109

Answers (1)

Anton Gorbunov
Anton Gorbunov

Reputation: 1444

  1. You shouldn't replace backslashes p.StartInfo.FileName = mainPath.Replace("\\", "/");, because windows use \ for pathes
  2. You definre variable var targetPath ut do not use it in the future.
  3. If you want put path in variable you might use @ for escaping cpecial-symbols, e.g. mainPath = mainPath + @"\TestStudio\Syncfusion.TestVisualBase.WPF\RecordAction\RecordAction.WPF\bin\Debug\RecordAction.WPF.exe";
  4. For concatinate pathes you may use Path.Combine() method
  5. Path for property p.StartInfo.FileName must starts from disc name e.g. C:\, or dot/s e.g. .\your_path or ..\parent_directory\your_path or starts from file or folder directly, relative current directory Directory.GetCurrentDirectory();

Upvotes: 1

Related Questions