Skip to content

Blazor WASM unmarshalled interop with JSImport #54946

Answered by pavelsavara
Hooterr asked this question in Q&A

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: 5 comments 29 replies

You must be logged in to vote
0 replies

You must be logged in to vote
2 replies
@Hooterr

@gismofx

Answer selected by Hooterr

You must be logged in to vote
16 replies
@maraf

maraf Oct 31, 2024
Collaborator

@legistek

@maraf

maraf Nov 1, 2024
Collaborator

@pavelsavara

@pavelsavara

You must be logged in to vote
11 replies
@gmurray81

@gmurray81

@legistek

@gmurray81

@gmurray81

You must be logged in to vote
0 replies
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
6 participants