Skip to content

Formatter throws when object has a pointer property #8765

@SeeminglyScience

Description

@SeeminglyScience

Steps to reproduce

$stream = $null
$peReader = $null
try {
    $stream = (Get-Item ([ref].Assembly.Location)).OpenRead()
    $peReader = [System.Reflection.PortableExecutable.PEReader]::new($stream)
    $memoryReader = $peReader.GetMetadata().GetReader()

    # yield
    $memoryReader
} finally {
    if ($null -ne $peReader) {
        $peReader.Dispose()
    }

    if ($null -ne $stream) {
        $stream.Dispose()
    }
}

Expected behavior

Length         : 4239440
Offset         : 0
RemainingBytes : 4239440
StartPointer   :
CurrentPointer :

Actual behavior

format-default : No coercion operator is defined between types 'System.Byte*' and 'System.Object'.
+ CategoryInfo          : NotSpecified: (:) [format-default], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.FormatDefaultCommand

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0-preview.3
PSEdition                      Core
GitCommitId                    6.2.0-preview.3
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Notes

PS> $Error[0].GetBaseException() | Format-List * -Force

Message        : No coercion operator is defined between types 'System.Byte*' and 'System.Object'.
Data           : {}
InnerException :
TargetSite     : System.Linq.Expressions.UnaryExpression
                 GetUserDefinedCoercionOrThrow(System.Linq.Expressions.ExpressionType,
                 System.Linq.Expressions.Expression, System.Type)
StackTrace     :    at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType,
                 Expression expression, Type convertToType)
                    at System.Management.Automation.Language.PSGetMemberBinder.WrapGetMemberInTry(Expression expr)
                    at System.Management.Automation.Language.PSGetMemberBinder.FallbackGetMember(DynamicMetaObject
                 target, DynamicMetaObject errorSuggestion)
                    at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters,
                 LabelTarget returnLabel)
                    at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
                    at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
                    at Microsoft.PowerShell.Commands.PSPropertyExpression.GetValue(PSObject target, Boolean
                 eatExceptions)
                    at Microsoft.PowerShell.Commands.PSPropertyExpression.GetValues(PSObject target, Boolean expand,
                 Boolean eatExceptions)
                    at Microsoft.PowerShell.Commands.Internal.Format.PSObjectHelper.GetExpressionDisplayValue(PSObject
                 so, Int32 enumerationLimit, PSPropertyExpression ex, FieldFormattingDirective directive,
                 StringFormatError formatErrorObject, PSPropertyExpressionFactory expressionFactory,
                 PSPropertyExpressionResult& result)
                    at Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator.GetExpressionDisplayValue(PSObject
                 so, Int32 enumerationLimit, PSPropertyExpression ex, FieldFormattingDirective directive,
                 PSPropertyExpressionResult& expressionResult)
                    at Microsoft.PowerShell.Commands.Internal.Format.ListViewGenerator.GenerateListViewEntryFromPropert
                 ies(PSObject so, Int32 enumerationLimit)
                    at Microsoft.PowerShell.Commands.Internal.Format.ListViewGenerator.GeneratePayload(PSObject so,
                 Int32 enumerationLimit)
                    at
                 Microsoft.PowerShell.Commands.Internal.Format.InnerFormatShapeCommand.WritePayloadObject(PSObject so)
                    at System.Management.Automation.CommandProcessor.ProcessRecord()
HelpLink       :
Source         : System.Linq.Expressions
HResult        : -2146233079

This does not reproduce on Windows PowerShell, instead the property is displayed as blank like expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions