加载System.Management.Automation程序集时出错

5

我正在开发一个WPF应用程序,其中运行了一个PowerShell脚本。

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, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"}**
当我搜索这个错误时,我能找到一些答案,但对我来说并不清楚。请给我建议。
1个回答

10

最终我成功解决了我的问题。以下是我采取的步骤:
打开我的.csproj文件
搜索System.Management.Automation引用。
将其替换为以下内容<Reference Include="System.Management.Automation" />
这些步骤成功解决了我的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接