Error loading System.Management.Automation assembly
Asked Answered
M

1

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.

Milliner answered 4/7, 2013 at 6:54 Comment(0)
M
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

Milliner answered 4/7, 2013 at 9:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.