Incompatibility with .Net Core 3.1.3, System.Text.JSON and Newtonsoft.JSON
See original GitHub issueProblem
While attemping to handle a shopify uninstall webhook, I came across this bug.
Error
the json value could not be converted to System.String. Cannot get the value of a token type ‘Number’ as a string
Config
- .Net Core 3.1.3
- ShopifySharp 5.1.0
Step to reproduce
- Setup an uninstall webhook and a Controller to handle the webhook
- Install your shopify app
- Uninstall your shopify app
startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
...
}
controller.cs
[HttpPost("uninstall")]
public async Task ExecuteUninstallWebhook([FromBody] Shop shop)
{
// throws the InvalidOperationException and a 400 BadRequest
}
Hotfix
As bypass you can set NewtonsoftJson as default formatter.
- Install Microsoft.AspNetCore.Mvc.NewtonsoftJson
- AddNewtonsoftJson to project. startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().AddNewtonsoftJson();
...
}
However this is setting NewtonsoftJson as default formattor, making the library incompatible with .Net Core 3.0 implementation of System.Text.JSON.
Suggestion
Migrate the library to System.Text.JSON to make it compatible with .Net Core 3.0 +
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Migrate from Newtonsoft.Json to System.Text.Json - .NET
System.Text.Json only accepts property names and string values in double quotes because that format is required by the RFC 8259 specification ...
Read more >System.Text.Json version conflict
Json dependency from .Net Core . Prior to .Net Core 3.x .Net Core had a dependency on Newtonsoft.Json. And also i see your...
Read more >Adding Newtonsoft JSON back to .NET Core 3.1 and Later
When developing .NET Core 3.1 applications or later, you may notice that Microsoft has changed to use the default dependency to System.Text.
Read more >Newtonsoft.Json vs System.Text.Json vs Json.Net : r/csharp
Json is enough for 99.9% of use cases. For the remaining 0.1% of demented and malformed JSON, Newtonsoft.Json will handle it better.
Read more >Updating my ASP.NET podcast site to System.Text.Json ...
NET Core 3.1 mainline. While most of my sites working and running just fine - the upgrade was easy - there was an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree, it should be added to the documentation. I need to go through the docs and get them updated, they’re currently a little bit out of date in some areas now that we’ve published v5.0.
Yeah, that’s what Stripe.net does. https://github.com/stripe/stripe-dotnet/blob/master/src/Stripe.net/Entities/_base/StripeEntity.cs#L95