7 Replies Latest reply on Sep 22, 2011 11:44 AM by mbonness

    Unhandled exception in Google Chrome

    vasmel
      Hello,

      After FeatureLayer receives invalid response from server exception in thrown:
      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)
        • Re: Unhandled exception in Google Chrome
          rlwatson
          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).
          • Re: Unhandled exception in Google Chrome
            JNery-esristaff
            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.
            • Re: Unhandled exception in Google Chrome
              vasmel
              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:
              (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:
                      var testconsole = {
                          testlog : function(arg){
                              alert(arg);
                          }
                      }
              

              SL:
              (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 :(
              • Re: Unhandled exception in Google Chrome
                JNery-esristaff
                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/silverlight-logging-extension-method.html

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

                "Firebug Lite will be loaded before all other scripts, allowing it to capture all console calls, and all XHR requests for that page"
                • Re: Unhandled exception in Google Chrome
                  rlwatson
                  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
                                          }
                                      }
                                  }
                              }
                          }
                  • Re: Unhandled exception in Google Chrome
                    JNery-esristaff
                    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/library/system.windows.browser.htmlpage.isenabled(v=VS.95).aspx
                    • Re: Unhandled exception in Google Chrome
                      mbonness
                      To fix the "Failed to InvokeSelf" error in Chrome I added the following Javascript to my page to override the default console.log() implementation:

                              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.

                              if (navigator.userAgent.indexOf("Chrome") > -1) {
                                  console.log = function(message) {
                                      // do nothing
                                  }
                              }


                      Hope this helps someone...