2009-09-02 5 views
1

Je suis en train de déboguer Silverlight 2 sur Firefox. Je reçois une erreur non gérée dans Firebug:L'exception Silverlight n'est pas traitée avec JS

Unhandled Error in Silverlight 2 Application 
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) 
at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
at MS.Internal.XcpImports.GetValue(INativeCoreTypeWrapper obj, DependencyProperty property) 
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason) 
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value) 
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) 
at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding) 
at System.Windows.FrameworkElement.SetBinding(DependencyProperty dp, Binding binding) 
at FileAudit.Page..ctor() 
at FileAudit.App.Application_Startup(Object sender, StartupEventArgs e) 
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) 
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) 

points ligne Silverlight.js 26 qui est

control = new ActiveXObject('AgControl.AgControl'); 

mon html est

<head> 
<script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script> 

<script type="text/javascript" src="/Silverlight.js"></script> 

<script type="text/javascript"> 
    function onSilverlightError(sender, args) { 

     var appSource = ""; 
     if (sender != null && sender != 0) { 
      appSource = sender.getHost().Source; 
     } 
     var errorType = args.ErrorType; 
     var iErrorCode = args.ErrorCode; 

     var errMsg = "Unhandled j Error in Silverlight 2 Application " + appSource + "\n"; 

     errMsg += "Code: " + iErrorCode + " \n"; 
     errMsg += "Category: " + errorType + "  \n"; 
     errMsg += "Message: " + args.ErrorMessage + "  \n"; 

     if (errorType == "ParserError") { 
      errMsg += "File: " + args.xamlFile + "  \n"; 
      errMsg += "Line: " + args.lineNumber + "  \n"; 
      errMsg += "Position: " + args.charPosition + "  \n"; 
     } 
     else if (errorType == "RuntimeError") { 
      if (args.lineNumber != 0) { 
       errMsg += "Line: " + args.lineNumber + "  \n"; 
       errMsg += "Position: " + args.charPosition + "  \n"; 
      } 
      errMsg += "MethodName: " + args.methodName + "  \n"; 
     } 

     $("#errorLocation").html(errMsg); 
    } 
</script> 
</head> 
<body> 
    <!-- Runtime errors from Silverlight will be displayed here. 
    This will contain debugging information and should be removed or hidden when debugging is completed --> 
    <div id="silverlightControlHost2"> 
     <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" 
      width="431" height="30" id="Xaml2"> 
      <param name="source" value="/ClientBin/FileAudit.xap" /> 
      <param name="onerror" value="onSilverlightError" /> 
      <param name="background" value="white" /> 
      <param name="minRuntimeVersion" value="2.0.31005.0" /> 
      <param name="autoUpgrade" value="true" /> 
      <param name="initParams" value="id=slPlugin1,embeddingTechnique=objectElement" /> 
      <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"> 
       <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" 
        style="border-style: none" /> 
      </a> 
     </object> 
     <iframe style='visibility: hidden; height: 0; width: 0; border: 0px'></iframe> 
    </div> 
    <div id='errorLocation' style="font-size: small; color: Gray;"> 
    </div> 

</body> 

Pourquoi est-il ne reçoivent pas traité dans JS et affiché dans errorLocation?
Désolé aussi mon formatage est nul.

+0

Cela fonctionne-t-il dans Internet Explorer et/ou lorsque vous exécutez Visual Studio ou Blend? – AnthonyWJones

Répondre

2

est venu avec une solution
Je suis allé au fichier App.xaml.cs et retravaillé la fonction Unhandled_Exception

Avec cela et un peu d'appel ce JS il était facile

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
    { 
     // If the app is running outside of the debugger then report the exception using 
     // the browser's exception mechanism. On IE this will display it a yellow alert 
     // icon in the status bar and Firefox will display a script error. 


     // NOTE: This will allow the application to continue running after an exception has been thrown 
     // but not handled. 
     // For production applications this error handling should be replaced with something that will 
     // report the error to the website and stop the application. 
     e.Handled = true; 

     try 
     { 
      ThrowRightError(e.ExceptionObject); 
      //System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight a 2 Application " + errorMsg + "\");"); 
     } 
     catch 
     { 
     } 

    } 
    private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) 
    { 
     try 
     { 
      ThrowRightError(e.ExceptionObject); 
      //System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");"); 
     } 
     catch (Exception) 
     { 
     } 
    } 

    private void ThrowRightError(Exception e) 
    { 
     string errorMsg = ""; 
     var exLayer = -1; 
     //errorMsg += String.Format("<br>Layer {0}<hr>", exLayer); 
     Exception ex2 = e; 
     while (ex2 != null) 
     { 
      errorMsg += "Message : <br />" + ex2.Message + "<br />Data :<br />" + ex2.Data + "<br />StackTrace :<br />" + ex2.StackTrace; 
      exLayer++; 
      errorMsg += String.Format("<br>Layer {0}<hr>", exLayer); 
      ex2 = ex2.InnerException; 
     } 
     errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"<br />"); 

     HtmlPage.Window.CreateInstance("foo2", new[] { errorMsg }); 
    } 

puis pour la JS

function foo2(theAlert) { 
    $("#errorLocation").html(theAlert); 
} 

Je me suis aussi ce que l'erreur d'origine était

ClientIdTextBlock.SetBinding(TextBox.TextProperty, ClientIdBinding); 

Une liaison de zone de texte pour un texte Bloc ... erreur stupide.

Questions connexes