Skip to content

Blazor WASM unmarshalled interop with JSImport #54946

Answered by pavelsavara
Hooterr asked this question in Q&A
Discussion options

You must be logged in to vote

At the moment we don't support marshaling structures with [JSImport].

The [JSMarshalAs<JSType.Any>] will marshal it as a proxy JS objects, just a wrapper around GCHandle.
That's why Blazor's deprecated unsafe pointer based platform.readStringField would not work on it.
We deprecated this because it was really unsafe, because GC could move the managed objects in memory.

You said that you have lot of data.
Possible solutions how you can transfer it:

  1. marshal each member of the structure as different parameter of JSImport method. Like void Method(string name, int year)
  2. if you have array of InteropStruct[] you can transform it into multiple arrays of simple types. And then marshal it as void …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Hooterr
Comment options

Answer selected by Hooterr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area-blazor Includes: Blazor, Razor Components
3 participants