Skip to content

Formatter throws when object has a pointer property #8765

Closed

Description

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.

Activity

  1. added
    Issue-Bug
    on Jan 28, 2019
  2. iSazonov commented on Jan 28, 2019

    @iSazonov
    Collaborator

    Dongbo Wang (@daxian-dbw) Is the Issue related #7788 and/or #7808?

  3. SeeminglyScience commented on Feb 1, 2019

    @SeeminglyScience
    ContributorAuthor

    Ilya (@iSazonov) They're pretty similar in nature, just different code paths.

    if (adapterData.member.DeclaringType.IsGenericTypeDefinition || adapterData.propertyType.IsByRefLike)
    {
    // This is kinda lame - we really should throw an error, but accessing property getter
    // doesn't throw error in PowerShell since V2, even in strict mode.
    expr = ExpressionCache.NullConstant;
    }

    At a glance, it looks like the above should be

    if (adapterData.member.DeclaringType.IsGenericTypeDefinition ||
        adapterData.propertyType.IsByRefLike ||
        adapterData.propertyType.IsPointer) 
    { 
        // This is kinda lame - we really should throw an error, but accessing property getter 
        // doesn't throw error in PowerShell since V2, even in strict mode. 
        expr = ExpressionCache.NullConstant; 
    } 

    Possibly also adapterData.propertyType.IsByRef.

  4. changed the title [-][BUG] Formatter throws when object has a pointer property[/-] [+]Formatter throws when object has a pointer property[/+] on Feb 16, 2019
  5. added
    WG-Engine
    on Feb 16, 2019
  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  9. added
    Resolution-No Activity
    on Nov 16, 2023
  10. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

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-BugResolution-No ActivityWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions