CommunityToolkit / Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier

Home Page:https://learn.microsoft.com/dotnet/communitytoolkit/maui

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] WeakReferenceMessenger breaking change: stopped working

softlion opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

weakmessenger messages are not received anymore

Expected Behavior

The message should be received

Steps To Reproduce

    public static async Task NavigateToSomething()
    {
        var tcs = new TaskCompletionSource<MyResult>();
        WeakReferenceMessenger.Default.Register<MyResult>(tcs, async (_,result) => 
        { 
            //Message never received
            WeakReferenceMessenger.Default.Unregister<MyResult>(tcs);
            tcs.TrySetResult(result);
        });

        await Navigation.PushModalAsync(new MyPage());
        var result = await tcs.Task;
        ...
    }

Link to public reproduction project repository

none

Environment

- .NET MAUI CommunityToolkit: 9.0.2
- OS: Android and iOS
- .NET MAUI: 8.0.70

Anything else?

I was able to repro that issue on an android simulator, and on an iOS device.
The exact same code was working as expected in previous versions of Community toolkit.

The only workaround is to replace the WeakReferenceMessenger by the StrongReferenceMessenger.

WeakReferenceMessanger is not in the .NET MAUI Community Toolkit.

Please open this issue in https://github.com/communitytoolkit/dotnet