Aspnetcore: Remove Newtonsoft.Json from the shared framework

Created on 27 Nov 2018  路  38Comments  路  Source: dotnet/aspnetcore

The following shared-framework libraries pull in Newtonsoft.Json:

  • [x] - Microsoft.AspNetCore.Mvc.ViewFeatures
  • [x] - Microsoft.Extensions.Configuration.Json
  • [x] - Microsoft.Extensions.DependencyModel
  • [x] - Microsoft.IdentityModel.JsonWebTokens
  • [x] - Microsoft.AspNetCore.SignalR.Protocols.Json
  • [x] - Microsoft.AspNetCore.Authentication.OAuth
  • [x] - Microsoft.Extensions.Logging.EventSource

These assemblies and dependencies need to be updated to remove their dependency on Newtonsoft.Json.

accepted area-platform breaking-change

Most helpful comment

Hiding a reference assembly isn't actually too hacky. We might have to do this for other assemblies anyways, per https://github.com/dotnet/corefx/issues/34906#issuecomment-459540531

All 38 comments

Tracking external issues:

Internal changes needed:

  • @Tratcher - update Microsoft.AspNetCore.Authentication.OAuth
  • @rynowak @mkArtakMSFT - we need to update Microsoft.AspNetCore.Mvc.ViewFeatures to make sure it doesn't pull in Newtonsoft.Json.
  • Update our dependency on IdentityModel.

Also adding @mkArtakMSFT to help with MVC's dependency on Json.net and myself to coordinate with partners on getting Json.net removed.

/cc @ahsonkhan and @steveharter who will have a porting-guide.md (soon) to assist with this

Adding @BrennanConroy for Microsoft.AspNetCore.SignalR.Protocols.Json

JsonDocument doesn't help us, we need the serializer and deserializer :)

Also, was there ever a discussion/decision for the netstandard issue?

@joshfree @ahsonkhan @steveharter?

Yea there鈥檚 a source version of the reader and writer for ns2.0

Also, was there ever a discussion/decision for the netstandard issue?

Yea there鈥檚 a source version of the reader and writer for ns2.0

https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.Bcl.Json.Sources

It contains the JsonDocument as well.

For guidance on consuming the source pacakge, visit: https://aka.ms/json-source-package-guide.

JsonDocument is now available to our builds.

Looks like DependencyModel has removed Json.Net, Oauth and Config.Json are in the works (https://github.com/aspnet/AspNetCore/pull/7105, https://github.com/aspnet/Extensions/pull/1028) and I believe SignalR is done (https://github.com/aspnet/AspNetCore/pull/6977). I think we'll be able to complete this for Preview 3.

I believe SignalR is done

I could be wrong, but I think the JsonProtocol is still waiting on serializer/deserializer feature being worked on atm.

Ah, missed that. Ok, so maybe not that close. @BrennanConroy what would be the impact of removing Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson from the shared framework? Are you planning to add a new assembly for a non-JSON.NET implementation of the json protocol?

https://github.com/aspnet/AspNetCore/blob/09e019841c2ff70c14a0ceb2958b1fc4e6bd0c8a/src/Framework/Microsoft.AspNetCore.App.props#L72-L75

SignalR not nearly done. A serializer is required.

Are you planning to add a new assembly for a non-JSON.NET implementation of the json protocol?

Yes.

what would be the impact of removing Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson from the shared framework?

Worst case is we remove the reference in preview3 and require customers to have to add a reference to either the NewtonsoftJson protocol or MessagePack protocol package for signalr to work at all.

Do you have a rough ETA on this? I want to know how bad it would be if we did this for Preview 3. For MVC in Preview 2, we removed the NewtonsoftJson package from the framework. If SignalR is the only thing keeping Json.Net in, I would be tempted to remove it even it means users have to add a new package.

Not committing to this...just thinking out loud.

For MVC in Preview 2, we removed the NewtonsoftJson package from the framework.

Yeah but it was easier for them because MVC continues to work without the package. Whereas SignalR just doesn't function anymore.

Do you have a rough ETA on this?

We can remove the reference whenever we want, so I suggest we wait until near the end of preview3 to see if we can get the new protocol in.

I'd also be fine to ask users to add the dependency directly for Preview3. cc @bradygaster in case he has any objections.

We just need a SignalR template 馃槵

@davidfowl i adore this idea. What would you want to say in said template? I'd prefer to have a template and a scaffolder so we could add it in after-the-fact, too.

Worst case is we remove the reference in preview3 and require customers to have to add a reference to either the NewtonsoftJson protocol or MessagePack protocol package for signalr to work at all.

This seems a little painful for customers but if we message it broadly maybe it wouldn't sting so much. want me to start a twitter poll to see if it'd freak folks out? If we can avoid this I'd prefer not randomize customers?

w.r.t. @davidfowl and my aspiration for templates - would it behoove us to augment the existing templates to add a "add signalr?" option? That, when enabled, would lay down everything a customer needs?

@BrennanConroy is it realistic that we could fix this by the end of p3 or p4?

@bradygaster It's not really in my control. We are blocked on corefx getting the serializer and deserializer in.

@BrennanConroy ah ok - thanks for the info & context. will discuss during triage.

I don't want to be hasty and make things too hard for customers. I'm trying to weigh this against front-loading breaking changes, such as removing Newtonsoft.Json from the framework.

If serializier/deserializer API's aren't coming in time for preview 3, there is an alternative. We could exclude Newtonsoft.Json from the targeting pack, but keep it in the runtime while SignalR waits for the new API. I think this lessens the impact while still moving us in the right direction. SignalR would still have the Json protocol implmentation in-box, but if customers wanted to use Newtonsoft.Json in other parts of their code, they would need to add a PackageReference to it.

The only problem with removing the ref and keeping the implementation is that SignalR exposes Json.Net types in two places:

Kind | Name | ReturnType | Assembly
---|---|---|---
Property | Microsoft.AspNetCore.SignalR.NewtonsoftJsonHubProtocolOptions.PayloadSerializerSettings | Newtonsoft.Json.JsonSerializerSettings | Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson
Property | Microsoft.AspNetCore.SignalR.Protocol.NewtonsoftJsonHubProtocol.PayloadSerializer | Newtonsoft.Json.JsonSerializer | Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson

My opinion on adding a SignalR template: We should carefully analyze the cost/benefit ratio before deciding to have one. It's not clear to me what it even look like. Perhaps if scaffolding existed to add SignalR would be a good middle ground, but even that would have costs.

@natemcmaster Wouldn't that be more "hacky" in the build system? We should probably completely yank it out and tell people to add the referene manually. I believe we'll have some form of serialization/deserialization in P4. The problem of keeping it in in some form is that we know the full effects of removing it until P4.

Hiding a reference assembly isn't actually too hacky. We might have to do this for other assemblies anyways, per https://github.com/dotnet/corefx/issues/34906#issuecomment-459540531

Perhaps if scaffolding existed to add SignalR would be a good middle ground, but even that would have costs.

I'd prefer just litter all the templates with "opt-in" functionality for SignalR, which'd drop in what they need in Startup.cs and a sample Hub class. Yes, there's a cost, but I think we should start thinking about when to pay that cost. I'll set up another issue for us to use to discuss this idea, so we can re-focus this thread on the issue at hand.

A SignalR template would be fine tbh, we resisted it for long but it would be a useful starting point as there's lots of moving pieces

Added Microsoft.Extensions.Logging.EventSource to the list at the top of this issue

cc @pakrym

Microsoft.AspNetCore.Authentication.* are done.

This did not make it into preview3 and is being pushed out to preview4.

@pranavkm can you please confirm whether this is done already?

we need to update Microsoft.AspNetCore.Mvc.ViewFeatures to make sure it doesn't pull in Newtonsoft.Json.

Was this page helpful?
0 / 5 - 0 ratings