Skip to content

Blazor: IJSRuntime.InvokeAsync serialization broken for arrays of objects #8743

@oliversturm

Description

@oliversturm

I have a simple JavaScript helper:

window.debugOut = (content) => {
  console.dir(content);
}

On the Blazor side I have this type:

public class City
{
  public string CityName { get; set; }
  public int Population { get; set; }
}

If I call the JavaScript debugOut and pass a List<City>, this arrives correctly on the browser side:

await Js.InvokeAsync<bool>("debugOut", new List<City> {
  new City{CityName="London",Population=8000000 },
  new City{CityName="Edinburgh", Population=400000 }
});

image

But if I use an array type instead, the browser only sees the first object:

await Js.InvokeAsync<bool>("debugOut", new City[] {
  new City{CityName="London",Population=8000000 },
  new City{CityName="Edinburgh", Population=400000 }
});

image

Serialization works correctly with an array of simple values. The problem seems to occur only with arrays of objects.

await Js.InvokeAsync<bool>("debugOut", new int[] { 1, 2, 3 });

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions