diff --git a/Oqtane.Client/Modules/Controls/Label.razor b/Oqtane.Client/Modules/Controls/Label.razor
index edccb9de..0d32a14b 100644
--- a/Oqtane.Client/Modules/Controls/Label.razor
+++ b/Oqtane.Client/Modules/Controls/Label.razor
@@ -1,8 +1,6 @@
@namespace Oqtane.Modules.Controls
@inherits ModuleControlBase
-@using Microsoft.AspNetCore.Http
@using Microsoft.Extensions.Localization
-@inject IHttpContextAccessor HttpContextAccessor
@if (!string.IsNullOrEmpty(HelpText))
{
@@ -54,10 +52,15 @@ else
var moduleType = Type.GetType(ModuleState.ModuleType);
var localizerTypeName = $"Microsoft.Extensions.Localization.IStringLocalizer`1[[{moduleType.AssemblyQualifiedName}]], Microsoft.Extensions.Localization.Abstractions";
var localizerType = Type.GetType(localizerTypeName);
- var localizer = (IStringLocalizer)HttpContextAccessor.HttpContext.RequestServices.GetService(localizerType);
-
- ChildContent = @@localizer[$"{ResourceKey}.Text"];
- HelpText = localizer[$"{ResourceKey}.{nameof(HelpText)}"];
+
+ // HACK: Use ServiceActivator instead of injecting IHttpContextAccessor, because HttpContext throws NRE in WebAssembly runtime
+ using (var scope = ServiceActivator.GetScope())
+ {
+ var localizer = (IStringLocalizer)scope.ServiceProvider.GetService(localizerType);
+
+ ChildContent = @@localizer[$"{ResourceKey}.Text"];
+ HelpText = localizer[$"{ResourceKey}.{nameof(HelpText)}"];
+ }
}
}
}
diff --git a/Oqtane.Client/Oqtane.Client.csproj b/Oqtane.Client/Oqtane.Client.csproj
index eaff964a..515bf8f5 100644
--- a/Oqtane.Client/Oqtane.Client.csproj
+++ b/Oqtane.Client/Oqtane.Client.csproj
@@ -32,7 +32,6 @@
-
diff --git a/Oqtane.Client/Program.cs b/Oqtane.Client/Program.cs
index 7d3ea0a7..d442141d 100644
--- a/Oqtane.Client/Program.cs
+++ b/Oqtane.Client/Program.cs
@@ -26,7 +26,6 @@ namespace Oqtane.Client
builder.Services.AddSingleton(httpClient);
builder.Services.AddOptions();
- builder.Services.AddHttpContextAccessor();
// Register localization services
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
@@ -89,8 +88,11 @@ namespace Oqtane.Client
.ToList()
.ForEach(x => x.ConfigureServices(builder.Services));
}
+ var host = builder.Build();
- await builder.Build().RunAsync();
+ ServiceActivator.Configure(host.Services);
+
+ await host.RunAsync();
}
private static async Task LoadClientAssemblies(HttpClient http)
diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs
index f5c5e07b..2cff1aa0 100644
--- a/Oqtane.Server/Startup.cs
+++ b/Oqtane.Server/Startup.cs
@@ -231,6 +231,8 @@ namespace Oqtane
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
+ ServiceActivator.Configure(app.ApplicationServices);
+
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();