2017-11-29 9 views
1

WPFウィンドウでホストされているWFコントロールを持つアプリケーションがあり、プロジェクトでいくつかのレコードおよび再生アクションを処理しています。私は再生を実行中に以下の例外を受け取ります。mscorlib.dllで 'System.ComponentModel.Win32Exception'型の未処理の例外が発生しました

私はこれについて検索し、またこれを試してみました私たちはprocess.Iへのファイルの完全なパスを提供する必要があるいくつかの提案を見てきました

ファイルが指定された見つけるが、それでも私は」することはできませんシステムこの例外が発生しました。

これを解決する方法を教えてもらえますか?

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(); 

窓が将来的にそれを使用しないでくださいあなたは、変数var targetPath UTをdefinre pathes

  • ため\を使用するので、あなたは、バックスラッシュp.StartInfo.FileName = mainPath.Replace("\\", "/");を置き換えるべきではないおかげで、

  • +1

    サイドノート:なぜあなたは 'Path.Combine'を使用していませんか?これらのスラッシュの前と後のすべての必要はありません。あなたの人生を楽にします。 – Blacktempel

    答えて

    1
    1. パスを変数に入れたい場合は、エスケープするために@を使用することができます。 mainPath = mainPath + @"\TestStudio\Syncfusion.TestVisualBase.WPF\RecordAction\RecordAction.WPF\bin\Debug\RecordAction.WPF.exe";プロパティp.StartInfo.FileName必見は、例えばディスク名から始まるためにあなたがPath.Combine()方法
    2. パスを使用することができconcatinate pathesについては
    3. C:\、またはドット/ s。 .\your_pathまたは..\parent_directory\your_pathまたは直接ファイルやフォルダから始まり、相対カレントディレクトリDirectory.GetCurrentDirectory();
    +1

    こんにちは@Anton、 ご意見ありがとうございます。 あなたが言ったように、私はバックスラッシュを置き換えません。私が使用したパスは以下の通りです "E:¥TestStudio¥WindowsForms_Testing¥TestStudio¥Syncfusion.TestVisualBase.WPF¥RecordAction¥RecordAction.WPF¥bin¥Debug¥RecordAction.WPF.exe" 同じエラー。何か悪いですか? – Prithiv

    +1

    私はこのようにそれを与える場合は、 p.StartInfo.FileName = @ "E:\ TestStudio \ WindowsForms_Testing \ WPF \ TestStudio \ Syncfusion.TestVisualBase.WPF \ RecordAction \ RecordAction.WPF \ binに\デバッグ\ RecordAction.WPF.exe "; 正常に動作します。私の実際の実装に何か問題はありますか? – Prithiv

    +0

    最初と2番目のコメントのパテントが異なります。最初のケースでは、 "E:\ TestStudio \ WindowsForms_Testing \ TestStudio"というフォルダを使用しますが、2回目にはE:\ TestStudio \ WindowsForms_Testing \ ** WPF ** \ TestStudio \ –

    関連する問題