You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am using Blazored.LocalStorage in version 4.5.0 in .NET9.
While I am able to read and write with ILocalStorageService on any razor page, I have troubles in reading values in WebAssemblyHost extension. This also holds true for the sync version ISyncLocalStorageService.
This is my extension
public static async Task<WebAssemblyHost> InitLanguage(this WebAssemblyHost host)
{
var localStorage = host.Services.GetRequiredService<ILocalStorageService>();
var result = await localStorage.GetItemAsStringAsync(StorageNames.CurrentCulture);
if (result == null)
{
await localStorage.SetItemAsStringAsync(StorageNames.CurrentCulture, "en-US");
}
...
return host;
}
StorageNames is a static class holding my strings, so I don't mix up names:
public static class StorageNames
{
public const string CurrentCulture = "currentCulture";
}
and this is my program.cs (shortened) that calls the extension:
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.InitLog()
.InitServices();
var host = builder.Build();
await host.InitLanguage();
await host.RunAsync();
I do register LocalStorage with builder.Services.AddBlazoredLocalStorage();.
My issue: In the extension the result value is always null and thus after the check the string "en-US" is written.
And this is the weird part for me: It will write it, but not read it.
When I manually edit the value currentCulture in Chrome Developer Mode and restart the application, the value will be overwritten to "en-US" again.
What am I doing wrong here?
The text was updated successfully, but these errors were encountered:
Hi, I am using
Blazored.LocalStorage
in version4.5.0
in.NET9
.While I am able to read and write with
ILocalStorageService
on any razor page, I have troubles in reading values inWebAssemblyHost
extension. This also holds true for the sync versionISyncLocalStorageService
.This is my extension
StorageNames
is a static class holding my strings, so I don't mix up names:and this is my
program.cs
(shortened) that calls the extension:I do register
LocalStorage
withbuilder.Services.AddBlazoredLocalStorage();
.My issue: In the extension the
result
value is alwaysnull
and thus after the check the string"en-US"
is written.And this is the weird part for me: It will write it, but not read it.
When I manually edit the value
currentCulture
in Chrome Developer Mode and restart the application, the value will be overwritten to"en-US"
again.What am I doing wrong here?
The text was updated successfully, but these errors were encountered: