【问题标题】:VS2010 Just in time debugger doesn't show entire messageVS2010 及时调试器不显示整个消息
【发布时间】:2013-02-20 08:14:56
【问题描述】:

我经常看到 Just-in-time 调试器窗口,而且大多数情况下没有显示任何消息,但有时我看不到整个异常,这可能很有用。

当我尝试运行调试器时,我总是收到另一个调试器已经连接的错误,这导致我无处可去。窗口无法调整大小,文本无法复制。

我在 VS 2010 + C# + Silverlight 中进行开发,它在通过 VS 运行时发生。

有什么见解吗?

【问题讨论】:

  • 尝试 ctrl-c 并粘贴到记事本中。应复制包括整个异常消息在内的对话框内容。

标签: visual-studio-2010 silverlight visual-studio-debugging


【解决方案1】:

您得到“另一个调试器已连接”,因为您已经处于调试模式并且您的浏览器进程已附加到您的代码。

首先, 处理 App.xaml 中的全局异常

其次,在您的浏览器中打开开发人员检查器。 (大多数浏览器为 F12)和观察控制台。

http://msdn.microsoft.com/en-us/library/system.windows.application.unhandledexception(v=vs.95).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-3

使用 System.IO; // FileNotFoundException 使用 System.Windows; // 应用程序、StartupEventArgs、ApplicationUnhandledExceptionEventArgs

 namespace SilverlightApplication
   {
   public partial class App : Application
    {
    public App()
    {
        this.Startup += this.Application_Startup;
        this.UnhandledException += this.Application_UnhandledException;

        InitializeComponent();
    }

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        this.RootVisual = new Page();
    }

    private void Application_UnhandledException(object sender, 
        ApplicationUnhandledExceptionEventArgs e)
    {
        if (e.ExceptionObject is FileNotFoundException)
        {
            // Inform the user

            // Recover from the error
            e.Handled = true;
            return;
        }

        // Exception is unrecoverable so stop the application and allow the 
        // Silverlight plug-in control to detect and process the exception.
    }
}

}

其次,在浏览器中打开开发者检查器。 (大多数浏览器为 F12)和观察控制台。 该消息来自您的 xap 托管的 index.aspx。有个silverlighterror js函数响应吧。

            function onSilverlightError(sender, args) {
        var appSource = "";
        if (sender != null && sender != 0) {
          appSource = sender.getHost().Source;
        }

        var errorType = args.ErrorType;
        var iErrorCode = args.ErrorCode;

        if (errorType == "ImageError" || errorType == "MediaError") {
          return;
        }

        var errMsg = "Unhandled Error in Silverlight 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";
        }

        throw new Error(errMsg);
    }

最后,始终确保(如果存在)在您的 Web 项目的设置中。在 Web 部分有一个 Silverlight 复选框用于调试。必须检查调试附件。

更多线索: 在 VS Ctrl + Alt + E 中,然后选择 CLR exceptions ,当您启动时,您将获得有关错误的更多详细信息。但是在准确发生错误的地方进行。因为它有时会给出非错误,但会被调试器捕获。

希望有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多