Info property for Streams property of Powershell instance is not available compiletime

So, a very strange problem.

Using VS2015 and .net 4.52

I developed this PowerShell C # code, it runs a script and catches the output. eg:

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 computer with Windows 10 pro), no problem.

Until I received a new machine (surface pro 4, as well as 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" that accepts the first argument of type "PSDataStreams" can be found (do you miss the use directive or assembly reference?)

It is all based on TFS, so I'm sure this is the same code.

If I define the definition on two machines, the problem becomes obvious:

enter image description here

So, I commented on the non-compiled code and ran it to see what happens at runtime:

enter image description here

So, the property is. Has anyone got a good explanation for this?

BTW: msdn documentation does not mention information property.

+5
source share
1 answer

You may be referring to the wrong version of the System.Management.Automation.dll assembly on Surface Pro.

In my installation of Windows 10 Pro (upgraded from Windows 8.1), I have two versions , one in each PAC :

2 ps versions

The one selected in the picture is “old”, lives in the old GAC ( C:\windows\assembly ) and identifies itself with the file version 6.1.7600.16385.

Another (which contains the correct version of PSDataStreams and provides the Information stream) lives in C:\Windows\Microsoft.NET\assembly and has a file version of 10.0.10240.16384 from the moment of writing.

+7
source

Source: https://habr.com/ru/post/1238755/


All Articles