Exception thrown: 'System.Exception' in ChakraBridge.winmd failed to start debugging

290 Views Asked by At

I am trying to load javascript in my app using ChakraBridge and I followed the steps given in the following block

Using JavaScript Framework in UWP

and also on GitHub JsBridge

I added ChakraBridge.winmd as reference in my project and it works perfectly fine when debug mode is Script. When I change it to Managed Only, it gives me exception and same for Release mode.

Can someone suggest what is the issue?

Here is the example. I am trying to assign default date in DatePicker in my project using ChakraBridge API

if (!string.IsNullOrEmpty(javascriptFunction))
{
    try
    {
        ChakraHost dateHost = new ChakraHost();
        string dateValue = dateHost.RunScript(javascriptFunction);
        var finalDate = DateTime.ParseExact(dateValue, "dd-MM-yyyy", CultureInfo.InvariantCulture);
        datePicker.Date = finalDate.Date;
    }
    catch(Exception ex)
    {
         Debug.WriteLine(ex.Message);
    }
}

The javascript function is

function executeScript(){var now = new Date(new Date().getTime() - (7*24*60*60*1000)); return ('0'+now.getDate()).substr(-2)+'-'+('0'+(now.getMonth()+1)).substr(-2)+'-'+now.getFullYear();} executeScript();

StackTrace I get

at ChakraBridge.ChakraHost..ctor()
at MCS.MCSDynamicViewBuilder.<GenerateDynamicControlforMobile>d__10.MoveNext()

Also, it works fine when I debug in my laptop machine and When I debug in mobile or in Mobile Emulator, it gives me this exception. Is it due to dist folder available on my laptop machine from where I refrence ChakraBridge.winmd?

1

There are 1 best solutions below

17
On BEST ANSWER

Yeah, I can reproduce your issue while using Mobile Emulator and setting "Debugger type" to "Managed Only". Following is the exception throws at ChakraHost dateHost = new ChakraHost();.

An exception of type 'System.Exception' occurred in ChakraBridge.winmd but was not handled in user code

Additional information: failed to start debugging.

In ChakraBridge, it calls JsStartDebugging to start debugging in the current context if it's in debug mode.

#if DEBUG
    // Debug
    if (Native.JsStartDebugging() != JavaScriptErrorCode.NoError)
        throw new Exception("failed to start debugging.");
#endif

However, Native.JsStartDebugging method returns Fatal while using Mobile Emulator and setting "Debugger type" to "Managed Only". So we got above exception in our application.

This issue seem only happens in Mobile Emulator. While testing on Local Machine or Device, both can work. According to the code, this error should only occur in Debug Mode. And if we add the ChakraBridge project in our solution, the app can run in Release Mode in Emulator. For now, you can test your app on Local Machine or a real Mobile Device and keep track of this issue on GitHub.