Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypedArray fail to serialize #5619

Closed
galvesribeiro opened this issue Oct 26, 2018 · 3 comments
Closed

TypedArray fail to serialize #5619

galvesribeiro opened this issue Oct 26, 2018 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. help wanted Up for grabs. We would accept a PR to help resolve this issue
Milestone

Comments

@galvesribeiro
Copy link
Member

Hello folks!

While I was implementing Blazor.Extensions.WebUSB, I had to send/receive buffers to the USB device connected. In C#, I was sending byte[] down to JS and it was working perfectly fine. However, when I was sending a buffer back from JS to C#, it fail without any errors since it was unable to deserialize the Uint8Array into a byte[]. It just hang on the resolve(array) call.

After a day trying to figure out what is going on, I noticed that if I convert it to a regular array it works perfectly with Array.prototype.slice.call(new Uint8Array(out.data.buffer)). That is very inefficient...

The reason for that (looks like) is because we don't have support to deserialize TypedArrays on SimpleJson...

The same problem happens on Blazor.Extensions.SignalR when we have a callback that expects a byte[].

Look at the examples here and here.

Do we have a less hacky/slow alternative to this?

Thanks!

@danroth27
Copy link
Member

Thanks for pointing this limitation out to us!

Do we have a less hacky/slow alternative to this?

Not that I'm aware of

@vertonghenb
Copy link
Contributor

vertonghenb commented Oct 30, 2018

Same issue with sending Enums up and down to JS(without parsing them to int).
However the performance loss is nothing compared to the arrays.

@aspnet-hello aspnet-hello transferred this issue from dotnet/blazor Dec 17, 2018
@aspnet-hello aspnet-hello added this to the Backlog milestone Dec 17, 2018
@aspnet-hello aspnet-hello added 1 - Ready area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. area-blazor Includes: Blazor, Razor Components help wanted Up for grabs. We would accept a PR to help resolve this issue labels Dec 17, 2018
@SteveSandersonMS
Copy link
Member

Check how Blazor's WebAssembly HTTP client deals with returning a large byte array from JS to C#.

Fundamentally you do have to copy the data at least once, because a JavaScript object isn't a .NET object and can't participate in the GC system directly. So for HTTP, the JS code asks the .NET code to allocate a byte[] of the desired size, then it copies the data into the .NET memory heap at that location.

@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. help wanted Up for grabs. We would accept a PR to help resolve this issue
Projects
None yet
Development

No branches or pull requests

6 participants