gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:25:22 26 4
gpt4 key购买 nike

我正在开发一个运行 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

但是当程序运行时出现以下异常;

Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)":"System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"}**

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

最佳答案

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

关于c# - 加载 System.Management.Automation 程序集时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17463679/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com