Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davicbaba opened this issue Dec 11, 2024 · 2 comments
Open

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

davicbaba opened this issue Dec 11, 2024 · 2 comments
Milestone

Comments

@davicbaba
Copy link

davicbaba commented Dec 11, 2024

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 davicbaba added the bug Something isn't working label Dec 11, 2024
@hoyosjs
Copy link
Member

hoyosjs commented Dec 12, 2024

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.

@tommcdon tommcdon added this to the 10.0.0 milestone Dec 12, 2024
@tommcdon tommcdon added documentation Documentation related issue Microsoft.Diagnostics.NETCore.Client and removed bug Something isn't working labels Dec 12, 2024
@tommcdon
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants