Page 1 of 1

Callback type not supported: System.Func`1[TResult]: Interop.ExecuteJavaScript("value=$0()", (Func<TResult>)myMethod)

Posted: Thu Aug 24, 2017 1:33 pm
by TaterJuice
I understand I can call a C# function from JS interop by calling

Code: Select all

Interop.ExecuteJavaScript("$0()", (Action)myCSMethod)


However, I need to be able to return a string, or an array, from my CS Function, so I tried replacing "Action" with "Func<string>" as seen below, but I receive the following error.

Code: Select all

Interop.ExecuteJavaScript("alert($0())", (Func<string>)myGetStringFunction)

Image

How do I pass a Value-Function, not an Action or void, to JS Interop?

Re: Callback type not supported: System.Func`1[TResult]: Interop.ExecuteJavaScript("value=$0()", (Func<TResult>)myMethod

Posted: Fri Aug 25, 2017 1:44 am
by JS-Support @Userware
Hi,

Thank you. It appears to be a Simulator issue. Does it work properly in the browser? We are going to look into it and keep you updated.

Regards
JS-Support

Re: Callback type not supported: System.Func`1[TResult]: Interop.ExecuteJavaScript("value=$0()", (Func<TResult>)myMethod

Posted: Fri Aug 25, 2017 7:56 am
by TaterJuice
No, I can't get it to work in the browser, I'm not sure if that problem is related, but when I try to run my JS output, I receive the following CONSOLE errors:

Code: Select all

JSIL.Browser.js?20178250855:201 Error: The function 'System.Void Vivrant.CSHTML5.WeatherPanel.WeatherPanelControlTemplate/<>c__DisplayClass8_0::<UpdateJSParticleConfig>b__1()' could not be translated.
    at Vivrant_CSHTML5_WeatherPanel_WeatherPanelControlTemplate_$l$gc__DisplayClass8_0.UntranslatableFunctionInvoked (JSIL.Core.js?20178250855:1228)
    at Delegate_Invoke (JSIL.Core.js?20178250855:9344)
    at CSharpXamlForHtml5.js?20178250855:55975
JSIL.Browser.WarningService.write @ JSIL.Browser.js?20178250855:201
JSIL.Browser.js?20178250855:199 Error: The function 'System.Void Vivrant.CSHTML5.WeatherPanel.WeatherPanelControlTemplate/<>c__DisplayClass8_0::<UpdateJSParticleConfig>b__1()' could not be translated.
    at Vivrant_CSHTML5_WeatherPanel_WeatherPanelControlTemplate_$l$gc__DisplayClass8_0.UntranslatableFunctionInvoked (JSIL.Core.js?20178250855:1228)
    at Delegate_Invoke (JSIL.Core.js?20178250855:9344)
    at CSharpXamlForHtml5.js?20178250855:55975
JSIL.Browser.WarningService.write @ JSIL.Browser.js?20178250855:199
JSIL.Host.js?20178250855:240 Uncaught Error: The function 'System.Void Vivrant.CSHTML5.WeatherPanel.WeatherPanelControlTemplate/<>c__DisplayClass8_0::<UpdateJSParticleConfig>b__1()' could not be translated.
    at Vivrant_CSHTML5_WeatherPanel_WeatherPanelControlTemplate_$l$gc__DisplayClass8_0.UntranslatableFunctionInvoked (JSIL.Core.js?20178250855:1228)
    at Delegate_Invoke (JSIL.Core.js?20178250855:9344)
    at CSharpXamlForHtml5.js?20178250855:55975

Re: Callback type not supported: System.Func`1[TResult]: Interop.ExecuteJavaScript("value=$0()", (Func<TResult>)myMethod

Posted: Tue Aug 29, 2017 8:20 am
by TaterJuice
This seems to be very "finicky".... I think part of my problem is this line:

Code: Select all

Interop.LoadJavascriptFile(@"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"");


This line works, but produces the "Non-Translatable Function" error when run in the browser.