-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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
- Create a File > New App (.NET MAUI project with .NET 10.0.100-preview.3.25201.16)
- Add Prism.DryIoc.Maui package version 9.0.537
- Create a ViewModel with PageDialogService dependency injection
- Add a Button with command binding to call DisplayAlertAsync
- Implement the DisplayAlertAsync call: await _dialogService.DisplayAlertAsync("Title", "Message", "OK", "Cancel");
- Run the app on Android emulator
- 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.