So.. very odd problem.
Using VS2015 and .net 4.52
I developed this C# powershell code, it is running a script and catches the output. like this:
using (PowerShell powerShellInstance = PowerShell.Create())
{
powerShellInstance.AddScript(scriptContents);
Collection<PSObject> PSOutput = powerShellInstance.Invoke();
if (powerShellInstance.Streams.Information.Count > 0)
{
foreach (var item in powerShellInstance.Streams.Information)
{
//do something with info
}
}
}
}
Compiles and runs (on a Windows 10 pro machine), no problems.
Until I got a new machine (surface pro 4, so also windows 10 pro) and tried to compile the code, I get this error:
'PSDataStreams' does not contain a definition for 'Information' and no extension method 'Information' accepting a first argument of type 'PSDataStreams' could be found (are you missing a using directive or an assembly reference?)
This is all TFS based, so I'm sure it is the same code.
If I goto definition on the two machines the problem becomes obvious:
So, I commented out the not compiling code and ran it, to see what was happening runtime:
So the property IS there.. Anybody got a good explanation for this?
BTW: the msdn documentation does not mention an Information property..
You might be referencing the wrong version of the System.Management.Automation.dll
assembly on the Surface Pro.
On my Windows 10 Pro installation (upgraded from Windows 8.1), I have two versions, one in each GAC:
The one selected in the picture is the "old" one, lives in the old GAC (C:\windows\assembly
) and identifies itself with the File Version 6.1.7600.16385.
The other one (which contains the correct version of PSDataStreams
and exposes the Information
stream) lives in C:\Windows\Microsoft.NET\assembly
and has File Version 10.0.10240.16384 as of writing.
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