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

Breaking changes to Microsoft.JSInterop #364

Open
pranavkm opened this issue Jun 3, 2019 · 0 comments
Open

Breaking changes to Microsoft.JSInterop #364

pranavkm opened this issue Jun 3, 2019 · 0 comments
Labels
3.0.0 Announcements related to ASP.NET Core 3.0 Announcement Breaking change

Comments

@pranavkm
Copy link
Contributor

pranavkm commented Jun 3, 2019

In 3.0-preview6, we're migrating Microsoft.JSInterop to use the System.Text.Json based serializer. As part of this transition, there are several breaking changes to the JSInterop library:

  • The helper type Microsoft.JSInterop.Json is being removed. Users may use a JSON serializer of their choice. We recommend using the System.Text.Json-based serializer since Blazor already references it. Here's the code change required to migrate to use System.Text.Json:
// Before
string value = Json.Serialize(...);
MyPoco poco = Json.Deserialize<MyPoco>("...");

// After
using System.Text.Json.Serialization;
...

string value = JsonSerializer.ToString(...);
MyPoco poco = JsonSerializer.Parse<MyPoco>("...");
  • DotNetObjectRef is replaced by a generic DotNetObjectRef<T> that is required for both sending and receiving a managed object reference when doing interop with the browser
// Before
IJSRuntime.InvokeAsync("SomeJSMethod", new DotNetObjectRef(someObject));

[JSInvokable]
public static Task SomeDotNetMethod(MyObject myObject)
{
    ...
}

// After
IJSRuntime.InvokeAsync("SomeMethod", DotNetObjectRef.Create(someObject));

[JSInvokable]
public static Task SomeDotNetMethod(DotNetObjectRef<MyObject> myObject)
{
    ...
}
  • Microsoft.JSInterop will use System.Text.Json to marshal interop data. To customize serialization, you may use serialization primitives such as JsonPropertyNameAttribute, JsonIgnoreAttribute etc.

  • IJSRuntime.UntrackObjectRef(DotNetObjectRef); has been removed. To stop tracking an object reference, dispose the DotNetObjectRef<T> instance either on the server or the client.

Please use dotnet/aspnetcore#10810 for further discussions.

@pranavkm pranavkm added Announcement Breaking change 3.0.0 Announcements related to ASP.NET Core 3.0 labels Jun 3, 2019
@aspnet aspnet locked and limited conversation to collaborators Jun 3, 2019
@mkArtakMSFT mkArtakMSFT removed their assignment Sep 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.0.0 Announcements related to ASP.NET Core 3.0 Announcement Breaking change
Projects
None yet
Development

No branches or pull requests

3 participants