🐛 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]
🐛 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
OnMessageItemsUpdatedAsynchas been subscribed to:fluentui-blazor/src/Core/Components/MessageBar/Services/MessageService.cs
Line 266 in 0625bb0
This happens in
FluentMessageBarProvider.OnInitialize:fluentui-blazor/src/Core/Components/MessageBar/FluentMessageBarProvider.razor.cs
Line 93 in 0625bb0
💻 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