+ Reply to Thread
Results 1 to 8 of 8

Thread: Unhandled exception in Google Chrome

  1. #1
    Vasyl Melnychuk
    Join Date
    Jun 2010
    Posts
    12
    Points
    3
    Answers Provided
    0


    0

    Default Unhandled exception in Google Chrome

    Hello,

    After FeatureLayer receives invalid response from server exception in thrown:
    Code:
    System.InvalidOperationException: Failed to InvokeSelf.
       at System.Windows.Browser.ScriptObject.InvokeSelf(Object[] args)
       at ESRI.ArcGIS.Client.Log.WriteLog(String message)
       at ESRI.ArcGIS.Client.Log.Write(String message, Exception exception)
       at ESRI.ArcGIS.Client.Layer.OnInitializationFailed(EventArgs e)
       at ESRI.ArcGIS.Client.Layer.Initialize()
       at ESRI.ArcGIS.Client.FeatureLayer.info_Error(Object sender, TaskFailedEventArgs e)
       at ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo.OnError(Exception err)
       at ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo.FromJson(String json)
       at ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo.Execute_Completed(Object sender, DownloadStringCompletedEventArgs e)
       at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
       at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)
    This only happens in Google Chrome. I can handle this exception in Application.UnhandledException but FeatureLayer.InitializationFailed event is not rising.


    Does anyone know how to disable or configure this logging (ESRI.ArcGIS.Client.Log)? (it is internal class)

  2. #2
    Richard Watson

    Join Date
    Nov 2009
    Posts
    1,617
    Points
    480
    Answers Provided
    71


    0

    Default Re: Unhandled exception in Google Chrome

    I have never used Chrome. If it has a console then turn it on. If it does not then try Firebug Lite.

    What I have seen is the ESRI logs various errors to the console (which is nice).

  3. #3
    Jennifer Nery

    Join Date
    May 2010
    Posts
    2,449
    Points
    289
    Answers Provided
    51


    0

    Default Re: Unhandled exception in Google Chrome

    The SL app did not fail with IE but failed in Google Chrome? Did IE also raise InitializedFailed event? Can you also add eventhandler for Initialized and see if FeatureLayer's InitializationFailure has a value? It's also good to use Fiddler or Firebug to know exactly where it failed during the webrequests.

    There should not be any difference in behavior with different web browsers. I just wonder if you were accessing a layer that is secured and maybe different web browsers handle authentication differently - that is a possibility.
    Jennifer Nery
    Software Developer
    ArcGIS API for SL/WPF/WP7

  4. #4
    Vasyl Melnychuk
    Join Date
    Jun 2010
    Posts
    12
    Points
    3
    Answers Provided
    0


    0

    Default Re: Unhandled exception in Google Chrome

    Quote Originally Posted by jenniferdnery View Post
    The SL app did not fail with IE but failed in Google Chrome? Did IE also raise InitializedFailed event? Can you also add eventhandler for Initialized and see if FeatureLayer's InitializationFailure has a value? It's also good to use Fiddler or Firebug to know exactly where it failed during the webrequests.

    There should not be any difference in behavior with different web browsers. I just wonder if you were accessing a layer that is secured and maybe different web browsers handle authentication differently - that is a possibility.
    SL app did not fail in IE and Firefox, but failed in Google Chrome. IE and FF raise InitializedFailed. InitializationFailure is not null it contain exception (and it is correct as web response is invalid, it is not valid feature layer json).

    I have made some test with console javascript object (as Richard wrote).
    And I think problem is with console.log function. I have tried this in Chrome:
    Code:
    (System.Windows.Browser.HtmlPage.Window.Eval("console.log") as System.Windows.Browser.ScriptObject).InvokeSelf(new object[] { "dummy message" });
    and it throws the same exception.

    Looks like ESRI.ArcGIS.Client.Log is trying to write message in the same way and fails.

    Also I have created my javascript function and tried to invoke it.
    Javascript:
    Code:
            var testconsole = {
                testlog : function(arg){
                    alert(arg);
                }
            }
    SL:
    Code:
    (System.Windows.Browser.HtmlPage.Window.Eval("testconsole.testlog") as System.Windows.Browser.ScriptObject).InvokeSelf(new object[] { "dummy message" });
    And it works fine.
    So SL fails to invoke only console.log, probalby a bug.
    However it is not good that exception is thrown by ESRI.ArcGIS.Client.Log during attempt to output debug information

  5. #5
    Jennifer Nery

    Join Date
    May 2010
    Posts
    2,449
    Points
    289
    Answers Provided
    51


    0

    Default Re: Unhandled exception in Google Chrome

    Thank you for sharing with us this information.

    We were not able to get InvalidOperationException() from using Google Chrome but we were able to replicate that InitializationFailed event is not raised, even when InitializationFailure is not null in Chrome. Like you said the other browsers, did not behave the same.

    Unfortunately, there's no way to disable logging in the current versions of our API. We will try to fix this in the future release to also handle the case when InvokeSelf() on ScriptObject may throw an exception.

    It seems like a known issue for Google Chrome as had been said in this blog: http://kodierer.blogspot.com/2009/05...on-method.html

    Firebug Lite extension can be found here: https://chrome.google.com/extensions...knfglimnifench

    "Firebug Lite will be loaded before all other scripts, allowing it to capture all console calls, and all XHR requests for that page"
    Jennifer Nery
    Software Developer
    ArcGIS API for SL/WPF/WP7

  6. #6
    Richard Watson

    Join Date
    Nov 2009
    Posts
    1,617
    Points
    480
    Answers Provided
    71


    0

    Default Re: Unhandled exception in Google Chrome

    Here is the function we use:

    private static void WriteLog(string message, string stackTrace)
    {
    if (HtmlPage.IsEnabled)
    {
    HtmlWindow window = HtmlPage.Window;
    var hasConsole = window.Eval("typeof(console) != 'undefined' && typeof(console.log) != 'undefined'");
    if (hasConsole is bool && (bool)hasConsole)
    {
    var console = window.Eval("console.log") as ScriptObject;
    if (console != null)
    {
    try
    {
    string messageToLog = FormatLogMessage(message, stackTrace);
    console.InvokeSelf(new object[] { messageToLog });
    }
    catch (InvalidOperationException)
    {
    // Google Chrome w/o FireBug lite
    }
    }
    }
    }
    }

  7. #7
    Jennifer Nery

    Join Date
    May 2010
    Posts
    2,449
    Points
    289
    Answers Provided
    51


    0

    Default Re: Unhandled exception in Google Chrome

    If you still wish to turn off logging, HtmlPage.IsEnabled is the property we check before ScriptObject.InvokeSelf() is called.
    http://msdn.microsoft.com/en-us/libr...(v=VS.95).aspx
    Jennifer Nery
    Software Developer
    ArcGIS API for SL/WPF/WP7

  8. #8
    Matt Bonness
    Join Date
    Sep 2011
    Posts
    2
    Points
    0
    Answers Provided
    0


    0

    Default Re: Unhandled exception in Google Chrome

    To fix the "Failed to InvokeSelf" error in Chrome I added the following Javascript to my page to override the default console.log() implementation:

    Code:
            if (navigator.userAgent.indexOf("Chrome") > -1) {
                console.log = function(message) {
                    alert(message);
                }
            }
    Now I get alerts with the actual error ("Tile load failed"). Since I don't care about this error I got rid of the alert() and now it fails silently using the Javascript below.

    Code:
            if (navigator.userAgent.indexOf("Chrome") > -1) {
                console.log = function(message) {
                    // do nothing
                }
            }
    Hope this helps someone...

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts