Reputation: 175
We are currently migrating our UI to Havit Blazor Components (awesome work, by the way! 🎉), and we are facing an issue with IHxMessageBoxService.
We are not using auto render mode (i.e., is not included in our application). However, when injecting IHxMessageBoxService in InteractiveServer or InteractiveWebAssembly render modes, it results in a null reference when calling ShowAsync().
🔍 Observed Behavior When injecting IHxMessageBoxService:
[Inject] protected IHxMessageBoxService MessageBox { get; set; }
Calling ShowAsync() throws a NullReferenceException.
🛠 Steps to Reproduce
builder.Services.AddHxServices();
builder.Services.AddHxMessenger();
builder.Services.AddHxMessageBoxHost();
@inherits LayoutComponentBase
<HxMessenger Position="ToastContainerPosition.TopEnd" />
<HxMessageBoxHost />
await MessageBox.ShowAsync("Title", "This is a test message.");
💡 Expected Behavior IHxMessageBoxService should be properly injected and work without errors in InteractiveServer or InteractiveWebAssembly render modes, even when auto render mode () is not used.
📸 Screenshot
(Attaching the error screenshot here for better visibility)
🛠 Troubleshooting Attempted ✅ Verified that AddHxMessageBoxHost() is registered correctly in Program.cs. ✅ Ensured is included in the LayoutComponentBase. ✅ Tested in Blazor Server and Blazor WebAssembly – both fail.
❓ Possible Cause Since IHxMessageBoxService works when using auto render mode (), but not in InteractiveServer or InteractiveWebAssembly, this suggests that the service may not be getting initialized properly when AddHxMessageBoxHost() is used outside the expected lifecycle.
It seems that the message box host might not be available in the component hierarchy when auto render mode is omitted.
📝 Environment
Any guidance would be much appreciated! 🙌
Upvotes: 0
Views: 15