I have a .NET 4.0 C# project where I need to run Powershell via C# in powershell runspace. I had tested my code it was all working good.
When opening same project on a new computer (Win10, VS2017) and trying to run same project getting issues. I have referenced the DLL on:
C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
Also doing this using commands
using System.Management;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
but System.Management.Automation and System.Management.Automation.Runspaces are not recognized.
Getting the error: The type or namespace name 'Automation' does not exist in the namespace 'System.Management' (are you missing an assembly reference?)
Somehow the references are not being used...
Not sure what exactly happens but when I was referencing the following DLL:
C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
VS was ignoring this DLL and complaining that we're missing the Automation namespace... although this DLL was showing as .NET 4.0, apparently it was compiled with a higher version of .NET which may explain why it was ignored.
To resolve the issue I had to add a reference by browsing and picking this DLL:
C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
which may seem like an older version of the powershell engine.
One more note which may have contributed to this is that on my new Win10 machine, I installed VS2017 so I did not manually install the .NET 4.0 FW and maybe the VS2017 installation puts higher version of the System.Management.Automation DLLs...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With