LocalStorage icon indicating copy to clipboard operation
LocalStorage copied to clipboard

[Bug] Lists of tuples are not being serialized correctly

Open PhilippJR opened this issue 1 year ago • 1 comments

Lists of tuples are not being serialized correctly.

Steps to reproduce:

  1. Create new Blazor Wasm project.
  2. Make Blazored.LocalStorage available
  3. Replace everything in Home.razor with the following code
@page "/"
@using Blazored.LocalStorage
@inject ILocalStorageService _localstorage

<button @onclick="SetLocalStorage">Click me</button>
@code {
    private async Task SetLocalStorage()
    {
        var entries = new List<(string, int)> { ("foo", 1), ("bar", 2), ("baz", 3) };
        entries.ForEach(item => Console.WriteLine($"{item.Item1}: {item.Item2}"));
        await _localstorage.SetItemAsync("foobarbaz", entries);

        entries = await _localstorage.GetItemAsync<List<(string, int)>>("foobarbaz");
        entries.ForEach(item => Console.WriteLine($"{item.Item1}: {item.Item2}"));
    }
}
  1. Run app and click button.
  2. See in the console, that the second time, the values are written to the console, they are not correct.
  3. In the dev tools, see that "foobarbaz" contains a list of tuples but the tuples are empty.

PhilippJR avatar Jan 29 '24 12:01 PhilippJR