VS2017中Xamarin应用进入中断模式问题排查咨询
Hey there, sorry to hear you're stuck with this vague "Application in Break Mode" issue while working through Xamarin tutorials in VS2017! Let's walk through some targeted debugging steps to uncover what's going on, since the error is popping up after your ParseAndDisplay method finishes executing.
Debugging Steps to Try
Enable Full Exception Breakpoints
VS2017 might be hiding exceptions that are being caught (but still causing issues). Go toDebug > Windows > Exception Settings(or pressCtrl+Alt+E), then check all boxes under Common Language Runtime Exceptions for both Thrown and User-unhandled. This will make VS pause at the exact line where any exception is triggered, even if it's wrapped in a try/catch block.Scour the Output Window
When you hit Break Mode, switch to the Output window (View > Output) and selectDebugfrom the dropdown at the top. Look for any error messages, stack traces, or Android native logs—often, vague break mode issues are tied to silent UI thread violations or resource cleanup errors that show up here.Step Through Code Line-by-Line Post-Method
Add a debug log at the very end ofParseAndDisplay:Console.WriteLine("ParseAndDisplay executed fully, exiting method");Then use
F11to step through every line right after the method finishes (like the rest of your button click event). This will help you pinpoint if the error is happening during UI updates, variable cleanup, or another post-method action.Validate UI Thread Access
Xamarin Android strictly requires all UI updates to happen on the main thread. IfParseAndDisplayuses async operations (like fetching JSON from a network), you might be accidentally updating UI elements off-thread after the method completes. Wrap any UI code inRunOnUiThreadto confirm:RunOnUiThread(() => { // Example: Update a TextView or ListView here myTextView.Text = parsedData.ToString(); });If you skip this, Android can throw silent exceptions that trigger break mode without clear messages.
Clean and Rebuild Your Solution
VS2017's Xamarin tooling can sometimes hold onto stale build artifacts that cause weird runtime issues. Go toBuild > Clean Solution, wait for it to finish, then doBuild > Rebuild Solutionbefore redeploying to your emulator or device.Add Global Exception Handlers
Catch unhandled CLR and Android-native exceptions by adding this code to yourMainActivity'sOnCreatemethod:// Catch .NET unhandled exceptions AppDomain.CurrentDomain.UnhandledException += (sender, e) => { var exception = e.ExceptionObject as Exception; Console.WriteLine($"Unhandled .NET Exception: {exception?.Message}\n{exception?.StackTrace}"); }; // Catch Android-native unhandled exceptions AndroidEnvironment.UnhandledExceptionRaiser += (sender, e) => { Console.WriteLine($"Android Unhandled Exception: {e.Exception.Message}\n{e.Exception.StackTrace}"); e.Handled = true; };These handlers will log detailed error messages to the Output window, even if the exception would otherwise trigger vague break mode.
If none of these steps reveal the issue, sharing the full code for your button click event and ParseAndDisplay method would help narrow things down further!
内容的提问来源于stack exchange,提问作者Peter Sun

