0

I've added in the reference to the Powershell dll (C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll); I've also removed that reference and opened up the Project File and added in <Reference Include="System.Management.Automation />. However, neither of these work, I always get the following error:

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)

Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Powershell_Execution
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (String str in PowerShell.Create().AddScript("Get-Process").AddCommand("Out-String").Invoke<String>())
            {
                Console.WriteLine(str);
            }



            Console.ReadLine();
        }
    }
}

Any ideas? Everything I've run across just said to add the <Reference Include="System.Management.Automation />, but that just produces the same runtime error.

Daniel Martin
  • 570
  • 1
  • 9
  • 18
  • possible duplicate of [Strong Name Validation Failed](http://stackoverflow.com/questions/403731/strong-name-validation-failed) – OldProgrammer Jan 02 '15 at 20:47
  • Try using Fuslogvw.exe tool to view binding issue error messages, could be due to incompatible key:http://msdn.microsoft.com/en-us/library/e74a18c4%28v=vs.110%29.aspx – Leslie Davies Jan 02 '15 at 21:14
  • @LeslieDavies unless I am misinterpreting how to use fuslogvw, nothing appears in the application logs when I run fuslogvw. – Daniel Martin Jan 02 '15 at 21:26
  • Run with admin privileges and go to Settings and select "Log all binds to disk" or "Log bind failures to disk" – Leslie Davies Jan 02 '15 at 21:29
  • @LeslieDavies Whoops didn't have "Log all binds to disk" checked, now stuff is popping up. I'll compare keys now thanks ! – Daniel Martin Jan 02 '15 at 21:32

1 Answers1

0

Your code work fine on my PC. I'm not sure what the problem obviously. But here , here and here

They solve your problem

Community
  • 1
  • 1