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

JsonConvert.DefaultSettings broke our code #10

Open
diegodemarco opened this issue Jul 27, 2022 · 1 comment
Open

JsonConvert.DefaultSettings broke our code #10

diegodemarco opened this issue Jul 27, 2022 · 1 comment

Comments

@diegodemarco
Copy link

diegodemarco commented Jul 27, 2022

Hi,

As it turns out after quite a lot of debugging, using this package broke our code, because it globally changes the way JsonConvert works. The code is in file Html2Pdf.cs (lines 95-99) and Screenshot.cs (lines 100-104), as shown below.

      JsonConvert.DefaultSettings = () => new JsonSerializerSettings
      {
        DefaultValueHandling = DefaultValueHandling.Ignore,
        NullValueHandling = NullValueHandling.Ignore
      };

The correct way to do this is NOT to change the global default configuration (because it affects every other piece of code in the solution), but to pass this configuration as a parameter when calling JsonConvert.SerializeObject(). In this way, you still have the same level of control, but you DO NOT affect how JsonConvert is used everywhere else. These changes should be done in lines Html2Pdf.cs (lines 106, 125, and 144), and Screenshot.cs (lines 111 and 130). The code shown above, which changes the default settings, should be removed altogether.

In short, changing de default settings of JsonConvert in a package is dangerous, and should be avoided, as it has side-effects in every piece of code outside the package as well, so JsonConvert.DefaultSettings SHOULD NOT be used. An example of this same problem in another package can be seen here:
Azure/azure-functions-signalrservice-extension#229

To solve this problem, we are now taking this code and adding it to our project instead of the package, including the changes that I mention above. That's all for the moment.

Cheers,
Diego

@kinetiq
Copy link

kinetiq commented Aug 4, 2022

Clearly, nobody is paying attention to this repo. If you contact them through their site or email, they are pretty responsive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants