Skip to content

fix: NullReferenceException in MessageService.ShowMessageBarAsync #4674

Closed

Description

🐛 Bug Report

I see about 30 NullReferenceException errors per week from MessageService.ShowMessageBarAsync in my app.

I have a component that references IMessageService and can call ShowMessageBarAsync. But this sometimes errors. I think the problem is ShowMessageBarAsync assumes that OnMessageItemsUpdatedAsync has been subscribed to:

await OnMessageItemsUpdatedAsync!.Invoke();

This happens in FluentMessageBarProvider.OnInitialize:

MessageService.OnMessageItemsUpdatedAsync += OnMessageItemsUpdatedHandlerAsync;

💻 Repro or Code Sample

🤔 Expected Behavior

No error.

😯 Current Behavior

There is a race between OnInitialize in the two controls causing NullReferenceExceptions.

💁 Possible Solution

MessageService doesn't call the event if it isn't registered?

Also, isn't AllMessages not thread safe? The lock around it just locks while accessing the property. A copy isn't being returned so a message could be added to it while the message bar provider is enumerating the collection, causing an error. Either a copy needs to be made here, or a copy is made each time the message list is modifed.

🔦 Context

🌍 Your Environment

  • OS & Device: [e.g. MacOS, iOS, Windows, Linux] on [iPhone 7, PC]
  • Browser [e.g. Microsoft Edge, Google Chrome, Apple Safari, Mozilla FireFox]
  • .NET and Fluent UI Blazor library Version [e.g. 8.0.2 and 4.4.1]

Activity

  1. added
    triage
    on Apr 5, 2026
  2. added
    bug
    status:needs-investigation
    and removed
    triage
    on Apr 6, 2026
  3. added a commit that references this issue on Apr 7, 2026
    7bdaf08
  4. added
    community:contribution
    on Apr 7, 2026
  5. added a commit that references this issue on Apr 7, 2026
    017b472
  6. added a commit that references this issue on Apr 7, 2026
    64d0d50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcommunity:contributionstatus:needs-investigation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions