Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 类型为';的未处理异常;System.ComponentModel.Win32Exception';发生在mscorlib.dll中_C#_Wpf_Winforms - Fatal编程技术网

C# 类型为';的未处理异常;System.ComponentModel.Win32Exception';发生在mscorlib.dll中

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

我有一个WF控件托管在WPF窗口中的应用程序,我正在我的项目中处理一些录制和回放操作。我在执行回放时遇到以下异常

系统找不到指定的文件

我对此进行了搜索,并看到了一些建议,建议我们需要提供要处理的文件的完整路径。我也尝试过这样做,但仍然遇到了这个异常

请告诉我如何解决这个问题

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,但以后不要使用它
  • 如果您想将path放入变量中,您可以使用
    @
    来转义cpeacial符号,例如
    mainPath=mainPath+@“\TestStudio\Syncfusion.TestVisualBase.WPF\RecordAction\RecordAction.WPF\bin\Debug\RecordAction.WPF.exe”
  • 对于concatatite路径,您可以使用
    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,感谢您的宝贵时间。我意识到我的错误并改正了它。现在它运行良好。