Skip to content

[BUG] PageDialogService.DisplayAlertAsync causes ArgumentNullException in .NET 10 #3337

@YukiNuno12

Description

@YukiNuno12

Description

When using Prism.Maui's PageDialogService.DisplayAlertAsync in .NET 10 environment, an ArgumentNullException occurs causing the application to crash. Despite passing clearly non-null string parameters, the cancel parameter is somehow converted to null within Prism's internal processing and causes an error when passed to MAUI's Page.DisplayAlertAsync.

Expected Behavior

Dialog should display normally and allow user to select "OK" or "Cancel"

Actual Behavior

App crashes with ArgumentNullException: Value cannot be null. (Parameter 'cancel')

Environment

  • .NET SDK: 10.0.100-preview.3.25201.16
  • Microsoft.Maui.Controls: 10.0.0-preview.3.25208.1
  • Prism.DryIoc.Maui: 9.0.537
  • Platform: Android

Code to Reproduce

MainPageViewModel.cs

using Prism.Commands;
using Prism.Mvvm;
using Prism.Services;

namespace PrismBugSample;

public class MainPageViewModel : BindableBase
{
    private readonly IPageDialogService _dialogService;

    public MainPageViewModel(IPageDialogService dialogService)
    {
        _dialogService = dialogService;
        ShowDialogCommand = new DelegateCommand(OnShowDialog);
    }

    public DelegateCommand ShowDialogCommand { get; }

    private async void OnShowDialog()
    {
        // This crashes in .NET 10 with ArgumentNullException
        await _dialogService.DisplayAlertAsync("Title", "Message", "OK", "Cancel");
    }
}

Relevant Log Output

FATAL EXCEPTION: main
Process: SimplePrismDialogApp.SimplePrismDialogApp, PID: 20105
android.runtime.JavaProxyThrowable: [System.ArgumentNullException]: Value cannot be null. (Parameter 'cancel')
    at Microsoft.Maui.Controls.Page.DisplayAlertAsync + 0x16(Unknown Source)
    at Microsoft.Maui.Controls.Page.DisplayAlert + 0x0(Unknown Source)
    at Prism.Services.PageDialogService.DisplayAlertAsync + 0x0(Unknown Source)
    at Prism.Services.PageDialogService.DisplayAlertAsync + 0x0(Unknown Source)
    at PrismBugSample.MainPageViewModel+<OnShowDialog>d__5.MoveNext + 0xf(Unknown Source)
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw + 0x11(Unknown Source)
    at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0 + 0x0(Unknown Source)
    at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 + 0x0(Unknown Source)

Analysis

Investigation reveals:

  • Input parameters are clearly non-null ("OK", "Cancel")
  • Direct MAUI call with same parameters works fine
  • Prism's internal processing somehow converts the cancel parameter to null
  • .NET 10's stricter null checking makes this issue visible

Steps to Reproduce

  1. Create a File > New App (.NET MAUI project with .NET 10.0.100-preview.3.25201.16)
  2. Add Prism.DryIoc.Maui package version 9.0.537
  3. Create a ViewModel with PageDialogService dependency injection
  4. Add a Button with command binding to call DisplayAlertAsync
  5. Implement the DisplayAlertAsync call: await _dialogService.DisplayAlertAsync("Title", "Message", "OK", "Cancel");
  6. Run the app on Android emulator
  7. Tap the button and observe the crash 🐞

Expected outcome: Dialog should display normally with "OK" and "Cancel" buttons, allowing user interaction
Actual outcome: App crashes with ArgumentNullException: Value cannot be null. (Parameter 'cancel')

Platform with bug

.Net MAUI

Affected platforms

Android

Did you find any workaround?

No, there is no practical workaround. While it's technically possible to bypass Prism and call MAUI's DisplayAlert directly, this defeats the purpose of using Prism's abstraction and testability benefits, so it's not a viable solution.

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions