Friday, 20 March 2015

The type or namespace name 'automation' does not exist in the namespace ''

I have added the reference Assembly System.Management.Automation in my C# application to run PowerShell scripts from C# project. but I am getting following error during compilation of the code.
Error 30 The type or namespace name 'Automation' does not exist in the namespace 'System.Management' (are you missing an assembly reference?)
This is my C# code:
using System.Management.Automation;
using System.Management.Automation.Runspaces;
static void Main(string[] args)
    Runspace runspace = RunspaceFactory.CreateRunspace();
    Pipeline pipeline = runspace.CreatePipeline();
    Collection<PSObject> results = pipeline.Invoke();
    StringBuilder stringBuilder = new StringBuilder();
    foreach (PSObject obj in results)


The issue was fixed after I have changed the reference of System.Management.Automation to c:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll.

I have added the reference Assembly System.Management.Automation from the location "C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0" and my C# projects targets .NET Framework 3.5. Initially I didn't find the the reference System.Management.Automation.dll when I search the Assemblies in Add Reference window, so that I have added the reference by manual browse option from the location "C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0".

Finally I found that the assembly file System.Management.Automation.dll (under the folder PowerShell 3.0) is supported only .NET Framework 4.0, so that have changed the reference Assembly to c:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll to fix this issue.


1 comment:

  1. In visual studio direct install of "" from NuGet Packages won't work it will show that error.

    You have to add:
    Microsoft PowerShell version (5/4/3/..) Reference Assembly.

    You can search for "PowerShell" in NuGet Packages Manager search bar