Skip to content

PSSessions with Containers throw NullReferenceException #13347

Closed

Description

@hemisphera

Cmdlets that deal with PSSessions created on ContainerId throw a NullReferenceException when creating the session. This is true for New-PSSession, Enter-PSSession and Invoke-Command, among maybe others.

The stack trace is this:

Object reference not set to an instance of an object.
   at System.Management.Automation.Runspaces.ContainerProcess.GetContainerProperties()
   at Microsoft.PowerShell.Commands.PSExecutionCmdlet.CreateHelpersForSpecifiedContainerSession()

For me the line that fails is inside GetContainerPropertiesInternal of the class System.Management.Automation.Runspaces.ContainerProcess in System.Management.Automation.dll.

ContainerObRoot = (string) computeSystemPropertiesType.GetProperty("ObRoot").GetValue(obj);

Steps to reproduce

To reproduce this a running container is required.

New-PSSession -ContainerId <TheContainerId> -RunAsAdministrator

Expected behavior

An instance of PSSession should be created.

Actual behavior

A NullReferenceException is thrown.

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Aug 4, 2020
  2. iSazonov commented on Aug 4, 2020

    @iSazonov
    Collaborator

    /cc Paul Higinbotham (@PaulHigin) Have you any thoughts about the issue?

  3. added
    WG-Engine
    Issue-Bug
    and removed
    Issue-Question
    on Aug 4, 2020
  4. PaulHigin commented on Aug 4, 2020

    @PaulHigin
    Contributor

    Yes, there have been some cases where container images do not contain the correct Hyper-V binaries needed for a PowerShellDirect connection. The Hyper-V team who owns these binaries are aware of the issue. But this problem is outside of PowerShell.

  5. added
    Resolution-External
    on Aug 4, 2020
  6. ghost closed this as completedon Aug 5, 2020
  7. hemisphera commented on Aug 6, 2020

    @hemisphera
    ContributorAuthor

    I am not sure on this Paul Higinbotham (@PaulHigin). How is this outside of PowerShell? The same container can be accessed without problems through a New-PSSession from PowerShell 5.1. It does look like a PS6/7+ problem to me, no?

  8. PaulHigin commented on Aug 6, 2020

    @PaulHigin
    Contributor

    The original issue description did not mention this. If WindowsPowerShell can connect to the same container using the same command:

    New-PSSession -ContainerId <TheContainerId> -RunAsAdministrator

    Then that would indicate a client error. But I am not aware of any changes to this code in either WindowsPowerShell or PowerShell core.

  9. PaulHigin commented on Aug 6, 2020

    @PaulHigin
    Contributor

    The only change I see in this code was made two years ago, to fix an incompatibility.

    PR #7883

    /cc Steve Lee (@SteveL-MSFT)

  10. hemisphera commented on Aug 6, 2020

    @hemisphera
    ContributorAuthor

    If WindowsPowerShell can connect to the same container

    Sorry, you're right: I did not mention it in the original description. But PS 5.1 is definitely able to access the same identical container. PS 7.0.0 and PS 7.0.3 can not.

  11. PaulHigin commented on Aug 6, 2020

    @PaulHigin
    Contributor

    Steve Lee (@SteveL-MSFT) Can you look at this and see if it is related to the fix you made for #7883?

  12. 1 remaining item

  13. SteveL-MSFT commented on Aug 6, 2020

    @SteveL-MSFT
    Member

    Following-up with Hyper-V team to see if they have changed their schema again as the code is trying to get Hyper-V properties, but ObRoot property is returning null.

  14. SteveL-MSFT commented on Aug 10, 2020

    @SteveL-MSFT
    Member

    The official answer from Hyper-V team is that they also changed this to a field from a property.

  15. added 4 commits that reference this issue on Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugMustHaveResolution-FixedWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions