Skip to content

TodoApp.MAUI: Replace obsolete Page.DisplayAlert with DisplayAlertAsync in AlertService (CS0618) #516

Closed

Description

@adrianhall

Summary

Discovered while adding Windows CI coverage for TodoApp.MAUI in #510 (PR #514, build-samples-todoapp-windows.yml). Building the sample produces a CS0618 obsolete-API warning:

Services\AlertService.cs(14,12): warning CS0618: 'Page.DisplayAlert(string, string, string)' is obsolete: 'Use DisplayAlertAsync instead'

Root cause

samples/todoapp/TodoApp.MAUI/Services/AlertService.cs:14:

public Task ShowErrorAlertAsync(string title, string message, string cancel = "OK")
    => Application.Current!.Windows[0].Page!.DisplayAlert(title, message, cancel);

.NET MAUI has deprecated the Task-returning Page.DisplayAlert(string, string, string) overload in favor of Page.DisplayAlertAsync(string, string, string), as part of a broader naming-consistency pass adding an explicit Async suffix to async MAUI APIs. The compiler warning itself names the replacement.

Additional information needed

None — this is a like-for-like rename with an identical signature/return type (Task), so it should be a mechanical, low-risk change. Worth double-checking the DisplayAlertAsync overload signature against the installed Microsoft.Maui.Controls package version (10.0.40, per the .csproj) once picked up, in case the parameter list or overload set differs slightly from DisplayAlert.

Suggested fix

Replace the call with the non-obsolete equivalent:

public Task ShowErrorAlertAsync(string title, string message, string cancel = "OK")
    => Application.Current!.Windows[0].Page!.DisplayAlertAsync(title, message, cancel);

Related

Activity

  1. Sahithbasani commented on Jul 10, 2026

    @Sahithbasani
    Contributor

    Hi! I'd like to work on this issue. If no one else is already working on it, I'd be happy to submit a PR.

  2. adrianhall commented on Jul 10, 2026

    @adrianhall
    CollaboratorAuthor

    thank you @Sahithbasani - much appreciated!

    there is an unrelated bug in the CI at the moment (macos-latest is out of step with the dotnet workloads for ios, which breaks the builds). However, I will fix that (since it is complicated).

  3. adrianhall commented on Jul 10, 2026

    @adrianhall
    CollaboratorAuthor

    Fixed in #528

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

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