2013-07-04 161 views
3

我正在開發運行PowerShell腳本WPF應用程序。錯誤加載System.Management.Automation裝配

string scriptPath = "/script/myscript.ps1"; 
Runspace runspace = RunspaceFactory.CreateRunspace(); 
runspace.Open(); 
Pipeline pipeline = runspace.CreatePipeline(); 
pipeline.Commands.AddScript(scriptPath); 
Collection<PSObject> results = pipeline.Invoke(); 

我已添加以下程序集。

C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll 

但是當程序運行下面的異常來了;

無法加載文件或程序集「System.Management.Automation,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35」或其某個依賴項。強名稱驗證失敗。 (從HRESULT異常:0x8013141A) 「:」 System.Management.Automation,版本= 3.0.0.0,文化=中性公鑰= 31bf3856ad364e35" } **

當我搜索這個錯誤,我可以找到一些答案。但是,這些都不清楚,我 請諮詢我

回答

5

最後我能解決我的問題,這是我做什麼;。
打開我的.csproj文件
搜索System.Management.Automation
用以下代碼替換<Reference Include="System.Management.Automation" />
這些步驟固定我的問題

+0

我還曾(VS快遞2012桌面)。謝謝。 – nothing9