Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Occasional NullReferenceException in Microsoft.PowerShell.ProgresPane.Hide() when updating multiple progress bars on PS 7.4.0 #21021

Copy link
Copy link
@kborowinski

Description

@kborowinski
Issue body actions

Prerequisites

Steps to reproduce

This is not happening on PS 5.1

Issue was first identified when expanding multiple 7z archives with Start-ThreadJob and Expand-7Zip cmdlet from 7Zip4PowerShell module. It might be also related to this issue with corresponding PR

Issue description:

When using a cmdlet that opens multiple progress panes on PS 7.4.0, a NullReferenceException is thrown occasionally on progress pan completion. Please refer to above links for more details.

Workaround:
Disable progress before calling cmdlet that opens multiple progress panes with $ProgressPreference = 'SilentlyContinue'

Expected behavior

NullReferenceException on ProgressPane completion should not happen

Actual behavior

Occasionally an exception is thrown that "Object reference not set to an instance of an object" at Microsoft.PowerShell.ProgressPane.Hide()

Error details

TargetSite      : Void Hide()
Message         : Object reference not set to an instance of an object.
Data            : {}
InnerException  :
HelpLink        :
Source          : Microsoft.PowerShell.ConsoleHost
Result          : -2147467261
StackTrace      :   at Microsoft.PowerShell.ProgressPane.Hide()
                    at Microsoft.PowerShell.ProgressPane.Show(PendingProgress pendingProgress)
                    at Microsoft.PowerShell.ConsoleHostUserInterface.HandleIncomingProgressRecord(Int64 sourceId, ProgressRecord record)
                    at Microsoft.PowerShell.ConsoleHostUserInterface.WriteProgress(Int64 sourceId, ProgressRecord record)
                    at System.Management.Automation.Internal.Host.InternalHostUserInterface.WriteProgress(Int64 sourceId, ProgressRecord record)
                    at System.Management.Automation.MshCommandRuntime.WriteProgress(Int64 sourceId, ProgressRecord progressRecord, Boolean overrideInquire)
                    at System.Management.Automation.Cmdlet.WriteProgress(ProgressRecord progressRecord) at SevenZip4PowerShell.ThreadedCmdlet.EndProcessing() in C:\Users\---\Documents\Visual Studio 2022\Projects\72ip4PowerShe11\72ip4Powershell\ThreadedCmdlet.cs:line 29

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 7.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

294245576-42cedbfa-b55a-413f-a955-e927ebb39adc


Edit: 2025-01-31

Script to reproduce the NRE's:

  1. Save as Test-ProgressBar.ps1
  2. Dot-source
  3. Execute Test-ProgressBar -Verbose to trigger NREs
  4. Execute Test-ProgressBar no errors
#Requires -Version 7.5 -Modules Microsoft.PowerShell.ThreadJob

function Test-ProgressBar {
    [CmdletBinding()]
    param()

    $Global:ProgressPreference = 'Continue'
    $PSStyle.Progress.MaxWidth = $Host.UI.RawUI.WindowSize.Width

    $splatThreadJob = @{
        ThrottleLimit = [Environment]::ProcessorCount
        StreamingHost = $Host
    }

    $isVerbose = $PSBoundParameters['Verbose'] -eq $true

    $threadJobs = 1..50 | ForEach-Object {
        Start-ThreadJob -Name $_ -ScriptBlock {
            try {
                $VerbosePreference = if ($Using:isVerbose) {'Continue'} else {'SilentlyContinue'}

                $progressBarId = $Using:_
                $progressBar = 'ProgressBar-{0}' -f $progressBarId

                foreach ($n in 0..100) {
                    Write-Progress -Activity $progressBar -Status ('{0}%' -f $n) -PercentComplete $n -Id $progressBarId
                    Start-Sleep -Milliseconds (Get-Random -Minimum 15 -Maximum 45)
                }
                Write-Progress -Activity $progressBar -Completed -Id $progressBarId

                Write-Verbose -Message (
                    'Progress bar completted: "{0}"' -f
                        $progressBar
                )
            } catch {
                # Write-Warning ('[PID: "{0}" | RID: "{1}"]' -f
                #     $PID,
                #     [Management.Automation.Runspaces.Runspace]::DefaultRunspace.Id,
                #     $_.Exception.Message
                # )
                # Wait-Debugger
                throw $_
            }
        } @splatThreadJob
    }

    $null = Wait-Job -Job $threadJobs | Receive-Job
    Remove-Job -Job $threadJobs -Force
}

Visuals:

Image

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.