Skip to content

Get-Error can hang on certain exceptions #21083

@jborean93

Description

@jborean93

Prerequisites

Steps to reproduce

There is something about the exception raised by Assembly.GetTypes() that is causing Get-Error to get stuck in some loop and use up all system resources. In dotnet 8 loading the System.Data.SqlClient causes an error when attempting to get the types of that assembly. While this is a known problem attempting to use Get-Error to produce more information causes the shell to hang and start to consume all the system resources.

I've narrowed it down to the formatting of this particular error record in the formatting code

. You can run this in pwsh with https://gist.github.com/jborean93/54a9c7fc999b13ddddaf36d716fe7916 to be able to step through the code that hangs. I haven't figured out what property on this particular exception is actually causing the problem but there is something there. My money is on Types or LoaderExceptions in $Error[0].Exception.InnerException.

Expected behavior

Add-Type -Assembly System.Data.SqlClient

# This will raise an exception
[System.Data.SqlClient.SqlCredential].Assembly.GetTypes()

# Calling Get-Error after "hangs"
Get-Error

Actual behavior

Shows the error without hanging

Error details

Nothing, it hangs

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Arch Linux
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions