Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error loading System.Management.Automation assembly

I am developing a WPF application which is running a powershell script.

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\3.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"}**

When I search this error I can find some answers. But those are not clear for me. Please advice me.

like image 985
New Developer Avatar asked Jul 04 '13 06:07

New Developer


1 Answers

Finally I was able to fix my issue. This is what I does;
open my .csproj file
search for System.Management.Automation reference.
Replace that with the following <Reference Include="System.Management.Automation" />
These steps fixed my issue

like image 165
New Developer Avatar answered Sep 28 '22 07:09

New Developer