您得到“另一个调试器已连接”,因为您已经处于调试模式并且您的浏览器进程已附加到您的代码。
首先,
处理 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 ,当您启动时,您将获得有关错误的更多详细信息。但是在准确发生错误的地方进行。因为它有时会给出非错误,但会被调试器捕获。
希望有所帮助!