LocalStorage icon indicating copy to clipboard operation
LocalStorage copied to clipboard

My attempts to read information from Blazored.LocalStorage fail.

Open MetodiEterov opened this issue 2 years ago • 1 comments

Describe the bug Hello,

I'm trying to use your solution for managing information in browser localstorage, but when I writing large amounts of information (about 35k!) to a variable in the localstorage, often my attempts to read it just stuck. This stuckking goes on indefinitely. I have followed your instructions when implementing your solution. No errors are generated for me. The application just stops. I can see and read the variable in the browser through the console, but not with your solution.

To Reproduce Steps to reproduce the behavior:

Added in Startup.cs file: services.AddBlazoredLocalStorage();

Injected the service in a Blazor component: [Inject] protected Blazored.LocalStorage.ILocalStorageService _localStorage { get; set; }

And called the service in OnAfterRenderAsync method: protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { var messages = await _localStorage.GetItemAsStringAsync("ServerMessages"); } }

No errors!!! The application stuck! The only error in a browser console is: "Error: Connection disconnected with error 'Error: Server returned an error on close: Connection closed with an error.'."(blazor.server.js)

Expected behavior I expect something simple: if errors occur, whatever their source, I need to be informed about them, and not somewhere something happens and I have to guess what it is...

Screenshots

Hosting Model (is this issue happening with a certain hosting model?): My application is based on Blazor Server, .Net 6.0 framework. I installed Blazored.LocalStorage Version="4.2.0".

MetodiEterov avatar May 12 '22 20:05 MetodiEterov

Hi, I'm having the same issue. Even if the row is in a try/catch block, I don't get any exception, just a disconnection from the server. Any Idea?

JSON size: 45k

@MetodiEterov Could be something related to DataModel? In mine there are: DateTime string Enum Dictionary<string, anotherclass> (this has the most records)

giovannigambino1980 avatar Jul 12 '22 08:07 giovannigambino1980

If one of you can provide a repro of the issue I can take a look.

chrissainty avatar Aug 27 '22 22:08 chrissainty

Same here. It is setting on the first run, then after that, it just freezes, no exceptions, it just disconnects. The application I have runs on a timer for 60 seconds, then refreshes the page.

As the first run means the cache is empty, it set's it fine. When the page is called again, it will not pass SomeModel = await _localStorage.GetItemAsync<SomeModel>("SomeModelCache"); and just hangs there, and appears to be disconnected.

However, it will process DateTime? cacheDate = await _localStorage.GetItemAsync<DateTime?>(SomeModelDateCache);

So I assume it is because I am trying to parse a complex object, as opposed to value or ref type???

It is setting the cache perfectly fine.

Unfortunately, I can't add a repo.

I am using Firefox: 104.0 (64-bit) VS22: Version 17.3.2 Blazored Storage: 4.2.0


'[Inject] public ILocalStorageService _localStorage { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
{
   if (firstRender)
   {
	if (!string.IsNullOrEmpty(DeviceName))
	{
		try
		{
			//This is where it stops on the next run. 
			SomeModel = await _localStorage.GetItemAsync<SomeModel>("SomeModelCache");
			DateTime? cacheDate = await _localStorage.GetItemAsync<DateTime?>(SomeModelDateCache);
			double totalTime = 0;
			
			if (cacheDate is not null)
			{
				totalTime = DateTime.UtcNow.Subtract((DateTime)cacheDate).TotalHours;
			}

			if (SomeModel is null || cacheDate is null || totalTime > 1)
			{
				await _localStorage.SetItemAsync<SomeModel>(SomeModelCache, someModelData);
				await _localStorage.SetItemAsync(SomeModelDateCache, DateTime.UtcNow);
			}
		}
		catch (Exception ex)
		{
			var stop = 1;
		}
	}
   }
}'

This is the config settings in Program.cs builder.Services.AddBlazoredLocalStorage(config => { config.JsonSerializerOptions.IgnoreReadOnlyProperties = true; config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip; config.JsonSerializerOptions.WriteIndented = true; });

OrangeGoblin1973 avatar Aug 31 '22 16:08 OrangeGoblin1973

Same issue when storage contains 35kb of json :(

NUlliiON avatar Sep 05 '22 11:09 NUlliiON

Seems more than 50 elements in the array

Ottenere Outlook per Androidhttps://aka.ms/AAb9ysg


From: Eugene @.> Sent: Monday, September 5, 2022 1:50:22 PM To: Blazored/LocalStorage @.> Cc: Giovanni Gambino @.>; Comment @.> Subject: Re: [Blazored/LocalStorage] My attempts to read information from Blazored.LocalStorage fail. (Issue #181)

Same issue when storage contains 35kb of json :(

— Reply to this email directly, view it on GitHubhttps://github.com/Blazored/LocalStorage/issues/181#issuecomment-1236898146, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARO5HUK22DFIKFVCGEZ2363V4XM75ANCNFSM5VZMIBUA. You are receiving this because you commented.Message ID: @.***>

giovannigambino1980 avatar Sep 05 '22 11:09 giovannigambino1980

Any update on this? I'm also having this issue. I have an object in local storage that contains a few lists and dictionaries and my server is just hanging with no real error. If I remove one of the dictionaries it works again. It seems to be related to the complexity of the object.

JonathanShrek avatar Sep 06 '22 16:09 JonathanShrek

https://github.com/JonathanShrek/BlazoredLocalStorageErrorExample

I've created a barebones repo to reproduce the issue. It seems to be occurring with complex objects.

JonathanShrek avatar Sep 06 '22 20:09 JonathanShrek

Thanks for providing a repro @JonathanShrek. I'm now about to go on holiday but I'll take a look at this once I'm back 👍

chrissainty avatar Sep 06 '22 21:09 chrissainty

Further digging revealed that the error was occurring at the "localStorage.getItem" .NET function call. I opened up a ticket with them and they responded referencing an old closed ticket here. My error was resolved by increasing the SignalR message size limit. I'll link my ticket that I logged with asp.net core in case it helps anyone else having the same issue.

https://github.com/dotnet/aspnetcore/issues/43974

JonathanShrek avatar Sep 14 '22 19:09 JonathanShrek

Thank you for providing that update, @JonathanShrek. This looks like it's the issue of the original post. I'm going to close this issue now as it's starting to get a bit messy and we have a solution now.

chrissainty avatar Sep 15 '22 12:09 chrissainty