'Breakpoints is not hitting while debugging a .NET MAUI android application

I have been working on a MAUI android application and when debugging, the breakpoints is not hitting and the application enter in a break state. But for windows app it works well. I think this is an issue with the .NET 6 Android Tooling in visual studio 2022. Is there any solutions for this problem ?



Solution 1:[1]

Here is a few steps I did to make things work with debugging MAUI Android apps. I was able to debug and get my regular exceptions and hit breakpoints after this.

  1. Add this code to Android platform main activity OnCreate method

    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

Then this hander method in the same class

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ System.Diagnostics.Debug.WriteLine(e.ToString());}
  1. Reset Your Exceptions for CLR. Shortcut is (Ctrl+Alt+E).

    Just double-click on the CLR Exceptions checkbox to reset.

enter image description here

  1. Disable Debug Your Code Only in Options

enter image description here

Solution 2:[2]

I was also having problems debugging some projects. (Preview 17.1.0) The ones that were failing had the following project settings.

<PropertyGroup>
    <TargetFrameworks>net6.0-ios;net6.0-android;net6.0-maccatalyst</TargetFrameworks> ...

Moving Android first fixed my problem

<PropertyGroup>
    <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks> ...

Solution 3:[3]

I had the same problem and it is now working, try this:

  1. Windows -> Settings -> Update & Security -> For Developers -> Developer Mode - On enter image description here

  2. Solution Properties -> Deploy - On enter image description here

  3. Visual Studio -> Tools -> Options -> Xml Hot Reaload -> Disable all enter image description here

  1. The you can just set your project has startup and run it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2
Solution 3 MarchalPT