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

本文关键字:出错 程序集 Automation System Management 加载 | 更新日期: 2023-09-27 18:21:00

我正在开发一个运行powershell脚本的WPF应用程序。

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=31bf3856a364e35"或其依赖项之一。强名称验证失败。(HRESULT:0x8013141A中的异常)":"System.Management.Automation,Version=3.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"}**

当我搜索这个错误时,我可以找到一些答案。但这些对我来说并不清楚。请给我建议。

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

我终于解决了我的问题。这就是我所做的
打开我的.csproj文件
搜索System.Management.Automation引用
将其替换为以下<Reference Include="System.Management.Automation" />
这些步骤修复了我的问题