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.

consider adding TypeNameHandling.All to the Json serialization settings

See original GitHub issue

I have a WebJob triggering from a queue message and the message argument is set as an abstract base type. As a result I get an exception saying that I could use a string and handle the serialization myself.

If the serialization settings for both serialize and deserialize had the TypeNameHandling set to All, then I believe the derived objects would be serialized correctly: new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }

Thank you, Paulo

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
christopherandersoncommented, Aug 15, 2016

We could probably expose a hook for the serializer settings to be changed.

1reaction
papintocommented, Aug 8, 2018

@HMoen I haven’t looked at this in a while but I think the only way to get around it is to create several messages for the different derived types (instead of a single one for the base type).

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeNameHandling setting
This sample uses the TypeNameHandling setting to include type information when serializing JSON and read type information so that the create types are...
Read more >
c# - is Newtonsoft TypeNameHandling.all with a basic ...
1 Answer 1 ... Which can be used as follows: var settings = new JsonSerializerSettings { SerializationBinder = new MySerializationBinder(), ...
Read more >
CA2326: Do not use TypeNameHandling values other than ...
This rule finds Newtonsoft.Json.TypeNameHandling values other than None . If you want to deserialize only when a Newtonsoft.Json.Serialization.
Read more >
Json.NET Serializer • Newtonsoft Serializer
A JSON serializer that uses Newtonsoft Json.NET. ... This feature requires the TypeNameHandling setting to be set to Auto or All .
Read more >
Adding $type to System.Text.Json Serialization like in ...
This article describes a technique to serialize models containing dynamic types with System.Text.Json JsonSerializer, that doesn't support ...
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