Uno.Wasm.Bootstrap
Uno.Wasm.Bootstrap copied to clipboard
Callback with string literal failing
I'm having trouble with a callback from JS to C#. The below JS function is called successfully, but the dispatch generates an error depending on the shape of the stringified JSON.
I'm passing a single parameter as a string, but it seems like it's trying to parse it as if it were a JSON object. I'm passing it as a string literal. I.e. .Validate('{"e":"a"}') not .Validate({"e":"a"})
Is there a way I can work around this error? I'd be happy for it to passthrough the stringified object as just a single string parameter.
This is the JS method that the metadata provider generated:
LuhnPageWasm.prototype.Validate = function(e) {
var parameters = {"e": e};
var serializedParameters = JSON.stringify(parameters);
Uno.Foundation.Interop.ManagedObject.dispatch(this.__managedHandle, "Validate", serializedParameters);
};
From this C# method
public void Validate(string e)
{
++KeyStrokeCounter;
Console.WriteLine("typed" + KeyStrokeCounter);
}
A JS call to the managed proxy passing this string succeeds:
WasmGenerator.LuhnPageWasm.activeInstances[2].Validate('{"e":{"s1":"blah"} }')
But if I pass this string, it generates an error:
WasmGenerator.LuhnPageWasm.activeInstances[2].Validate('{"e":{"s1":"blah","s2":"another"} }')
Error:
dotnet.js:1 Uncaught Error: System.Reflection.TargetParameterCountException: Arg_TargetParameterCountException
at System.Reflection.RuntimeMethodInfo.ConvertValues(:44339/Binder binder, Object[] args, ParameterInfo[] pinfo, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.RuntimeMethodInfo.Invoke(:44339/Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(:44339/Object obj, Object[] parameters)
at Uno.Foundation.Interop.JSObjectMetadataProvider.ReflectionMetadata.InvokeManaged(:44339/Object instance, String method, String jsonParameters)
at Uno.Foundation.Interop.JSObject.Dispatch(:44339/String handlePtr, String method, String parameters)
at Object._convert_exception_for_method_call (dotnet.js:1:184193)
at Object._handle_exception_for_call (dotnet.js:1:186162)
at Function.managed__Uno_Foundation_Runtime_WebAssembly__Uno_Foundation_Interop_JSObject_Dispatch [as dispatchMethod] (managed__Uno_Foundation_Runtime_WebAssembly__Uno_Foundation_Interop_JSObject_Dispatch:19:21)
at Function.ManagedObject.dispatch (ManagedObject.ts:121:18)
at LuhnPageWasm.Validate (eval at 590207 (dotnet.js:1:16530), <anonymous>:34:48)
at <anonymous>:1:47
I tried prepending a string that wasn't close to looking like JSON to try and get it to passthrough as-is, but it still fails.
Succeeds:
WasmGenerator.LuhnPageWasm.activeInstances[2].Validate("Don't parse me I'm just a string" );
Fails with same TargetParameterCountException:
WasmGenerator.LuhnPageWasm.activeInstances[2].Validate("Don't parse me I'm just a string {e:{one:'sdf',two:'sdfs'}}" );