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.

Anonymous types are not getting properly serialized

See original GitHub issue

The below request gets converted,

var extendedData = new[]
    {                
        new { Name = "foo", Value = 1 },
        new { Name = "bar", Value = 2 },
    };
request.ExtendedData = extendedData;

into following JSON

{"Data":"test","Monitoring":true,"ExtendedData":[{},{}]}

with SafeJsonConvert.SerializeObject. It works as expected with JsonConvert.Serialize method of JSON.NET.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
nrandellcommented, Mar 14, 2018

I’ve just found this and solved it by created a CustomInitialize that changes the contract resolver.

        partial void CustomInitialize()
        {
            SerializationSettings.ContractResolver = new DefaultContractResolver();
        }

My code is now working!

1reaction
brjohnstmsftcommented, Apr 15, 2016

Thanks for the details @keerthivasanm

I’ve made sure this issue is being triaged by the right people.

FYI @markcowl

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Serializing anonymous types - Stack Overflow
As such, anonymous types are not marked as serializable. Since the usage of binary serialization means you later on want to deserialize them,...
Read more >
Deployment Issue: Serialization Exception on Anonymous Type
The anonymous type I'm returning is the result of a LINQ to Entities query that uses a Select method to build the anonymous...
Read more >
Serialized anonymous classes using JsonUtility - Unity Forum
Most serializers require the class that is serialized to be marked with the System.Serializable attribute. Anonymous classes do not have this ...
Read more >
Casting object to Anonymous Types in C# - Mitch Valenta
In my test, I wanted to validate the data on one of the models in that anonymous type that is set in IActionResult's...
Read more >
On Lambdas, Anonymous Classes and Serialization in Java
One important aspect of serialization is that it does not apply to single instances but to graphs of objects. There is little value...
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