question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incompatibility with .Net Core 3.1.3, System.Text.JSON and Newtonsoft.JSON

See original GitHub issue

Problem

While attemping to handle a shopify uninstall webhook, I came across this bug.

image

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

  1. Setup an uninstall webhook and a Controller to handle the webhook
  2. Install your shopify app
  3. 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.

  1. Install Microsoft.AspNetCore.Mvc.NewtonsoftJson
  2. 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:open
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
nozzlegearcommented, Apr 20, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found