Error loading System.Management.Automation assembly

5

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.

c#
wpf
powershell
assemblybinding
asked on Stack Overflow Jul 4, 2013 by New Developer • edited Jul 4, 2013 by Ansgar Wiechers

1 Answer

10

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

answered on Stack Overflow Jul 4, 2013 by New Developer

User contributions licensed under CC BY-SA 3.0