New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F#-based library (Deedle) fails in PS #21372
Comments
It looks like PowerShell has an issue invoking methods with an It tries to call the method with Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public class MyClass
{
public static int TestMethod1(int defaultValue = 1) => defaultValue;
public static int TestMethod2([Optional] int defaultValue) => defaultValue;
public static int TestMethod1Implicit() => TestMethod1();
public static int TestMethod2Implicit() => TestMethod2();
}
'@
[MyClass]::TestMethod1() # works as pwsh supports default parameter values
[MyClass]::TestMethod2() # fails due to the issue you are seeing
# What pwsh is doing internally when it comes to default values and [Optional]
# Works with a default value
[MyClass].GetMethod('TestMethod1').Invoke($null, @([Type]::Missing))
# Fails with an [Optional] value
[MyClass].GetMethod('TestMethod2').Invoke($null, @([Type]::Missing)) We would have to find out how to invoke such a method to use the |
I've opened dotnet/runtime#100322 because it seems like this should potentially be fixed in .NET rather than PowerShell. In case they think it's not a bug and aren't wanting to fix it this diff when applied locally fixed PowerShell to work for methods with such attributes diff --git a/src/System.Management.Automation/engine/runtime/Binding/Binders.cs b/src/System.Management.Automation/engine/runtime/Binding/Binders.cs
index 3e3ec3fbc..62814ed77 100644
--- a/src/System.Management.Automation/engine/runtime/Binding/Binders.cs
+++ b/src/System.Management.Automation/engine/runtime/Binding/Binders.cs
@@ -7163,7 +7163,7 @@ namespace System.Management.Automation.Language
Diagnostics.Assert(parameters[i].IsOptional,
"if there are too few arguments, FindBestMethod should only succeed if parameters are optional");
var argValue = parameters[i].DefaultValue;
- if (argValue == null)
+ if (argValue == null || (!parameters[i].HasDefaultValue && argValue == Type.Missing))
{
argExprs[i] = Expression.Default(parameterType);
} I need to do some more in depth testing to ensure it works in other scenarios but I think it should be fine. |
.NET has said the behaviour is expected so I've opened #21387 to fix up PowerShell to call it with the |
Prerequisites
Steps to reproduce
I'm trying to use Deedle to work with various data
Expected behavior
should not crash
Actual behavior
Error details
Environment data
Visuals
The text was updated successfully, but these errors were encountered: