Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Information" property on Streams property of Powershell instance not available compiletime

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:

enter image description here

So, I commented out the not compiling code and ran it, to see what was happening runtime:

enter image description here

So the property IS there.. Anybody got a good explanation for this?

BTW: the msdn documentation does not mention an Information property..

like image 484
Flores Avatar asked Dec 20 '15 10:12

Flores


1 Answers

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:

2 ps versions

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.

like image 89
Mathias R. Jessen Avatar answered Nov 20 '22 02:11

Mathias R. Jessen