diagnostics icon indicating copy to clipboard operation
diagnostics copied to clipboard

Dump Generation Failure on Android in .NET MAUI Blazor Hybrid App

Open davicbaba opened this issue 11 months ago • 2 comments

I'm encountering an issue when generating a dump in my .NET MAUI Blazor Hybrid application on .NET 8 using the Microsoft.Diagnostics.NETCore.Client library. When the app runs on Windows, it works as expected, but when running on Android, I receive the following error:

My code:

 public async Task WriteDumpAsync()
    {
        string appDataDirectory = FileSystem.AppDataDirectory;
        string timestamp = DateTime.UtcNow.ToString("yyyyMMdd_HHmmss");
        string fileName = $"dump_{timestamp}.dmp";
        string dumpPath = Path.Combine(appDataDirectory, "dumps");

        int processId = Process.GetCurrentProcess().Id;
        DiagnosticsClient client = new DiagnosticsClient(processId);

        if (!Directory.Exists(dumpPath))
            Directory.CreateDirectory(dumpPath);

        DumpType dumpType = DumpType.Normal;

        // Attempt to write the dump
        await client.WriteDumpAsync(dumpType, Path.Combine(dumpPath, fileName), logDumpGeneration: false, CancellationToken.None);
    }

Result on android:

Microsoft.Diagnostics.NETCore.Client.ServerNotAvailableException: Unable to connect to Process 28258. Please verify that /data/user/0/com.companyname.androiddumpgeneration/cache/ is writable by the current user. If the target process has environment variable TMPDIR set, please set TMPDIR to the same directory. Please see https://aka.ms/dotnet-diagnostics-port for more information
   at Microsoft.Diagnostics.NETCore.Client.PidIpcEndpoint.GetDefaultAddress(Int32 pid)
   at Microsoft.Diagnostics.NETCore.Client.PidIpcEndpoint.GetDefaultAddress()
   at Microsoft.Diagnostics.NETCore.Client.PidIpcEndpoint.ConnectAsync(CancellationToken token)
   at Microsoft.Diagnostics.NETCore.Client.IpcClient.SendMessageGetContinuationAsync(IpcEndpoint endpoint, IpcMessage message, CancellationToken cancellationToken)
   at Microsoft.Diagnostics.NETCore.Client.IpcClient.SendMessageAsync(IpcEndpoint endpoint, IpcMessage message, CancellationToken cancellationToken)
   at Microsoft.Diagnostics.NETCore.Client.DiagnosticsClient.WriteDumpAsync(DumpType dumpType, String dumpPath, WriteDumpFlags flags, CancellationToken token)
   at AndroidDumpGeneration.Components.Pages.Home.WriteDumpAsync() in C:\Users\davic\OneDrive\Documentos\GitRepositories\net-maui-android-dump\AndroidDumpGeneration\Components\Pages\Home.razor:line 49
   at AndroidDumpGeneration.Components.Pages.Home.GenerateDumpAsync() in C:\Users\davic\OneDrive\Documentos\GitRepositories\net-maui-android-dump\AndroidDumpGeneration\Components\Pages\Home.razor:line 25

To verify directory access, I tried writing a simple .txt file to the /data/user/0/com.companyname.androiddumpgeneration/cache/ directory from my application, and it succeeded. This confirms I have write permissions to that directory. Given that I can write files there, it suggests that the issue might be related to the dump generation library on Android rather than a permissions or environment configuration problem

Steps to Reproduce

  1. Clone and open the AndroidDumpGeneration project.
  2. Run the application to an Android device or emulator.
  3. Navigate to the home page.
  4. Click the Generate Dump button.
  5. Observe the error displayed on screen.

Expected Result:
The dump should be generated successfully on Android.

Actual Result:
A runtime error occurs, and the dump is not generated.

Configuration

  • Target: .NET 8.0 Android
  • Tool/Library: Microsoft.Diagnostics.NETCore.Client version 0.2.553101
  • IDE: Visual Studio 2022
  • OS: Android (Emulator or Device)
  • Host Machine: Windows 11 x64

Repository that demostrates the issue:
https://github.com/davicbaba/net-maui-android-dump

davicbaba avatar Dec 11 '24 03:12 davicbaba

Android does not support collecting memory dumps. Additionally, that PID exists in the android context - so you can't use the client library directly like that. You connect to it via TCP - not via PID-derived sockets. If you were to do this, I'd still expect a reply from the runtime saying mono runtimes don't have support for collecting memory dumps.

hoyosjs avatar Dec 12 '24 00:12 hoyosjs

I've marked this item as needing documentation. I'm not sure if we publicly document that dumps are not supported on Android, so we can use this issue to track that.

tommcdon avatar Dec 12 '24 02:12 tommcdon

We should look into PNSE these methods as well.

steveisok avatar Sep 09 '25 18:09 steveisok