C# 类型为';的未处理异常;System.ComponentModel.Win32Exception';发生在mscorlib.dll中
我有一个WF控件托管在WPF窗口中的应用程序,我正在我的项目中处理一些录制和回放操作。我在执行回放时遇到以下异常 系统找不到指定的文件 我对此进行了搜索,并看到了一些建议,建议我们需要提供要处理的文件的完整路径。我也尝试过这样做,但仍然遇到了这个异常 请告诉我如何解决这个问题C# 类型为';的未处理异常;System.ComponentModel.Win32Exception';发生在mscorlib.dll中,c#,wpf,winforms,C#,Wpf,Winforms,我有一个WF控件托管在WPF窗口中的应用程序,我正在我的项目中处理一些录制和回放操作。我在执行回放时遇到以下异常 系统找不到指定的文件 我对此进行了搜索,并看到了一些建议,建议我们需要提供要处理的文件的完整路径。我也尝试过这样做,但仍然遇到了这个异常 请告诉我如何解决这个问题 var instance = testclass.GetControlForTest(); WindowsFormsHost host = new WindowsFormsHost(); host.Child = inst
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();
谢谢
p.StartInfo.FileName=mainPath.replace(“\\”,“/”代码>,因为windows对路径使用\
var targetPath
ut,但以后不要使用它@
来转义cpeacial符号,例如mainPath=mainPath+@“\TestStudio\Syncfusion.TestVisualBase.WPF\RecordAction\RecordAction.WPF\bin\Debug\RecordAction.WPF.exe”代码>
Path.Combine()
方法p.StartInfo.FileName
的路径必须从磁盘名开始,例如C:\
,或点/s,例如\u路径
或。\parent\u目录\u路径
或直接从文件或文件夹开始,相对当前目录目录.GetCurrentDirectory()代码>
旁注:为什么不使用
Path.Combine
?不需要在路径前后都有这些斜线。。。让你的生活更轻松。嗨@Anton,谢谢你的建议。现在我不会像你说的那样替换反斜杠。下面是我使用的路径,“E:\TestStudio\WindowsForms\U Testing\TestStudio\Syncfusion.TestVisualBase.WPF\RecordAction\RecordAction.WPF\bin\Debug\RecordAction.WPF.exe”,但我仍然收到相同的错误。有什么问题吗?如果我这样给出,p.StartInfo.FileName=@“E:\TestStudio\WindowsForms\u Testing\WPF\TestStudio\Syncfusion.TestVisualBase.WPF\RecordAction\RecordAction.WPF\bin\Debug\RecordAction.WPF.exe”;工作正常。我的实际实现中有什么错误吗?第一个和第二个注释中的路径是不同的。在第一种情况下,您使用文件夹“E:\TestStudio\WindowsForms\u Testing\TestStudio”,但在第二种情况下使用-E:\TestStudio\WindowsForms\u Testing\WPF\TestStudio\Hi@Anton,感谢您的宝贵时间。我意识到我的错误并改正了它。现在它运行良好。