Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/System.Management.Automation/engine/MshMemberInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2691,18 +2691,18 @@ private static Type GetMethodGroupType(MethodInfo methodInfo)
return typeof(Func<PSNonBindableType>);
}

var methodTypes = new Type[parameterInfos.Length + 1];
for (int i = 0; i < parameterInfos.Length; i++)
try
{
var parameterInfo = parameterInfos[i];
Type parameterType = parameterInfo.ParameterType;
methodTypes[i] = GetPSMethodProjectedType(parameterType, parameterInfo.IsOut);
}
var methodTypes = new Type[parameterInfos.Length + 1];
for (int i = 0; i < parameterInfos.Length; i++)
{
var parameterInfo = parameterInfos[i];
Type parameterType = parameterInfo.ParameterType;
methodTypes[i] = GetPSMethodProjectedType(parameterType, parameterInfo.IsOut);
}

methodTypes[parameterInfos.Length] = GetPSMethodProjectedType(methodInfo.ReturnType);
methodTypes[parameterInfos.Length] = GetPSMethodProjectedType(methodInfo.ReturnType);

try
{
return DelegateHelpers.MakeDelegate(methodTypes);
}
catch (TypeLoadException)
Expand Down
12 changes: 12 additions & 0 deletions test/powershell/Language/Interop/DotNet/DotNetInterop.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ namespace DotNetInterop
public MyByRefLikeType(int i) { }
public static int Index;
}

public class ExampleProblemClass
{
public void ProblemMethod(ref MyByRefLikeType value)
{
}
}
}
'@
if (-not ("DotNetInterop.Test" -as [type]))
Expand Down Expand Up @@ -229,6 +236,11 @@ namespace DotNetInterop
{ $testObj[1] = 1 } | Should -Throw -ErrorId "CannotIndexWithByRefLikeReturnType"
}

It "Create instance of type with method that use a ByRef-like type as a ByRef parameter" {
$obj = [DotNetInterop.ExampleProblemClass]::new()
$obj | Should -BeOfType DotNetInterop.ExampleProblemClass
}

Context "Passing value that is implicitly/explicitly castable to ByRef-like parameter in method invocation" {

BeforeAll {
Expand Down