Skip to content

DotNetAdapter fails to create PSMethod with a ByRef parameter of a ref struct #7786

@SeeminglyScience

Description

@SeeminglyScience

Steps to reproduce

Add-Type -TypeDefinition '
    using System.Runtime.CompilerServices;

    public ref struct MyTestStruct
    {
    }

    public class ExampleProblemClass
    {
        public void ProblemMethod(ref MyTestStruct value)
        {
        }
    }'

[ExampleProblemClass]::new()

Expected behavior

# The object goes through formatting successfully
ExampleProblemClass

Actual behavior

format-default : The following exception occurred while retrieving members: "The generic type 'System.Management.Automation.PSReference`1' was used with an invalid instantiation in assembly 'System.Management.Automation, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'."
+ CategoryInfo          : NotSpecified: (:) [format-default], ExtendedTypeSystemException
+ FullyQualifiedErrorId : CatchFromBaseGetMembers,Microsoft.PowerShell.Commands.FormatDefaultCommand

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Here's the stack trace

System.TypeLoadException: The generic type 'System.Management.Automation.PSReference`1' was used with an invalid instantiation in assembly 'System.Management.Automation, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   at System.Management.Automation.PSMethod.GetPSMethodProjectedType(Type type, Boolean isOut)
   at System.Management.Automation.PSMethod.GetMethodGroupType(MethodInfo methodInfo)
   at System.Management.Automation.PSMethod.CreatePSMethodConstructor(MethodInformation[] methods)
   at System.Management.Automation.PSMethod.Create(String name, DotNetAdapter dotNetInstanceAdapter, Object baseObject, MethodCacheEntry method, Boolean isSpecial, Boolean isHidden)
   at System.Management.Automation.DotNetAdapter.AddAllMethods[T](Object obj, PSMemberInfoInternalCollection`1 members, Boolean ignoreDuplicates)
   at System.Management.Automation.DotNetAdapter.GetMembers[T](Object obj)
   at System.Management.Automation.Adapter.BaseGetMembers[T](Object obj)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions