Description
Description
When using params keyword in combination with JSImport, generates Error CS0758 Both partial method declarations must use a params parameter or neither may use a params parameter
Reproduction Steps
I created a Console app and added Uno.Wasm.Boostrap:
<ItemGroup>
<PackageReference Include="Uno.Foundation.Runtime.WebAssembly" Version="5.0.19" />
<PackageReference Include="Uno.Wasm.Bootstrap" Version="8.0.3" />
<PackageReference Include="Uno.Wasm.Bootstrap.DevServer" Version="8.0.3" />
</ItemGroup>
Then added this code in Program.cs which has a successful call using an intermediate function which calls down to a JSImport'd function without params
keyword, then demonstrates the failure scenario where calling to a JSImport'd function directly with params
keyword does not work and generates compile time error:
using System.Runtime.InteropServices.JavaScript;
namespace DynamicReturnNoWorkInRelease;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
object data = JQueryProxy.SomeJSData();
GlobalJS.Console.Log("Data from C#:", data);// log using JSObject reference
// trying to call signature using `params` keyword
// Severity Code Description Project File Line Suppression State
// Error CS0758 Both partial method declarations must use a params parameter or neither may use a params parameter DynamicReturnNoWorkInRelease
// ..\Microsoft.Interop.JavaScript.JSImportGenerator\Microsoft.Interop.JavaScript.JSImportGenerator\JSImports.g.cs 68
GlobalProxy.Console.LogParams("Data from C#:", data);// log using JSObject reference
}
}
public static class GlobalJS
{
public static class Console
{
// Work around error by using intermediate function with params keyword, then calling JSImport'd func withou params keyword
public static void Log(params object[] parameters)
{
GlobalProxy.Console.Log(parameters);
}
}
}
internal static partial class GlobalProxy
{
internal static partial class Console
{
// Works successfully, but doesn't support params keyword
[JSImport("globalThis.console.log")]
public static partial void
Log([JSMarshalAs<JSType.Array<JSType.Any>>] object[] parameters);
// Results in error CS0758
[JSImport("globalThis.console.log")]
public static partial void
LogParams([JSMarshalAs<JSType.Array<JSType.Any>>] params object[] parameters);
}
}
Attempting to compile results in:
Severity Code Description Project File Line Suppression State
Error CS0758 Both partial method declarations must use a params parameter or neither may use a params parameter DynamicReturnNoWorkInRelease .\JSImportWithParams\Microsoft.Interop.JavaScript.JSImportGenerator\Microsoft.Interop.JavaScript.JSImportGenerator\JSImports.g.cs 68 Active
Expected behavior
I would expect this to work as deeper code should just see params object[]
as a object[]
Actual behavior
Attempting to compile results in:
Severity Code Description Project File Line Suppression State
Error CS0758 Both partial method declarations must use a params parameter or neither may use a params parameter DynamicReturnNoWorkInRelease .\JSImportWithParams\Microsoft.Interop.JavaScript.JSImportGenerator\Microsoft.Interop.JavaScript.JSImportGenerator\JSImports.g.cs 68 Active
Regression?
No
Known Workarounds
Sample code demonstrates workaround of using an additional intermediate call supporting the params type, and calling into the JSImport'd method without the params keyword.
Configuration
Running in Version 17.9.0 Preview 1.0 with final release of .NET 8 (not preview .NET 8). Compiled to WASM using Uno.Bootstrap, but as far as I understand it, the JSImport capability is provided by .NET.
Other information
My guess is this should go to area-System.Runtime.InteropServices.JavaScript