DrXSsive
DrXSsive

Reputation: 175

IHxMessageBoxService Injection Fails in InteractiveServer & InteractiveWebAssembly Render Modes - Havit Blazor

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

  1. Download and set up the Havit Blazor template.
  2. Follow all migration steps as per the documentation.
  3. Register the required services both in the main project and the client project:
builder.Services.AddHxServices(); 
builder.Services.AddHxMessenger(); 
builder.Services.AddHxMessageBoxHost();
  1. Inherit LayoutComponentBase in the layout: (just adding semis to reder code block)
@inherits LayoutComponentBase
<HxMessenger Position="ToastContainerPosition.TopEnd" /> 
<HxMessageBoxHost />
  1. Run the project in InteractiveServer or InteractiveWebAssembly mode.
  2. Try calling:
await MessageBox.ShowAsync("Title", "This is a test message.");
  1. Observe that MessageBox is null and ShowAsync() throws a NullReferenceException.

💡 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) enter image description here

🛠 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

  1. .Net core version: 9.0
  2. Havit: 4.7.2
  3. Blazor Mode: Blazor WebAssembly / Blazor Server
  4. Render Mode: InteractiveServer / InteractiveWebAssembly

Any guidance would be much appreciated! 🙌

Upvotes: 0

Views: 15

Answers (0)

Related Questions