【问题标题】:Silverlight errors showing in JavaScript, not Visual Studio在 JavaScript 中显示 Silverlight 错误,而不是在 Visual Studio 中
【发布时间】:2012-05-26 11:46:47
【问题描述】:

构建一个在浏览器中运行的 Silverlight 5 应用程序,但遇到一些在 JavaScript 中显示的烦人的错误,当附加调试器时,由于某种原因,它们没有被 Visual Studio 捕获。我已经完成了一些简单的事情(创建带有 Web 项目的 VS SL 5 项目)。当我调试时,错误通过 JS 显示在浏览器中......而不是在 Visual Studio 中。

我可以设置断点并遍历它们,但是当发生未处理的异常时,SL 只是在页面中冒泡(如预期的那样),但 VS 没有捕捉到它。

我已验证 VS 已附加到 IE 进程和 Type=Silverlight。现在我要解决的错误是令人讨厌的 4004 错误代码(category=managedruntimeerror),消息为“system.argumentexception:值不在预期范围内”,但我找不到发生这种情况的地方/ o 堆栈更详细。我得到的只是“Visual Studio JIT 调试器”,它看起来非常像 http://www.scottleckie.com/2010/04/code-4004-unhandled-error-in-silverlight-application/,但他的解决方案对我不起作用......

【问题讨论】:

    标签: silverlight debugging visual-studio-debugging


    【解决方案1】:

    查看您的 App.xaml.cs,您会发现一个名为 Application_UnhandledException 的处理程序。
    应该有一些类似这样的代码:

        Deployment.Current.Dispatcher.BeginInvoke(delegate
        {
            ReportErrorToDOM(e);
        });
    

    将其替换为您的自定义错误处理方法。
    ReporErrorToDOM 是在您的浏览器中触发 javascript 错误的原因。


    如果没有,您需要设置一个:

    public App()
    {
        this.UnhandledException += this.Application_UnhandledException;
        ...
    }
    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
        // Handle exception here
        ...
        // Don't forget this !
        e.Handled = true;
    }
    

    【讨论】:

    • 我想对我来说没有意义的是为什么在附加调试器时会发生这种情况。甚至 Application_UnhandledException 中的注释也说在附加调试器时不会发生这种情况。但是,这确实有所帮助,因为我能够查看发件人内部并查看我遇到的问题的根源。
    猜你喜欢
    • 1970-01-01
    • 2023-03-23
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多