wpf 加载 System.Management.Automation 程序集时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17463679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error loading System.Management.Automation assembly
提问by New Developer
I am developing a WPF application which is running a powershell script.
我正在开发一个运行 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();
I have added the following assembly.
我添加了以下程序集。
C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell.0\System.Management.Automation.dll
But when program runs following exception comes;
但是当程序运行时出现以下异常;
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"}**
无法加载文件或程序集“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"}**
When I search this error I can find some answers. But those are not clear for me. Please advice me.
当我搜索此错误时,我可以找到一些答案。但这些对我来说还不清楚。请给我建议。
回答by New Developer
Finally I was able to fix my issue. This is what I does;
open my .csprojfile
search for System.Management.Automation reference.
Replace that with the following <Reference Include="System.Management.Automation" />
These steps fixed my issue
最后我能够解决我的问题。这就是我所做的;
打开我的.csproj文件
搜索 System.Management.Automation 参考。
将其替换为以下<Reference Include="System.Management.Automation" />
这些步骤解决了我的问题

