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.

Using Json.NET library suggestion

See original GitHub issue

First of all, thank you for the fantastic library! I have a suggestion for the creation of Bson Document in the following events in Audit.Net MongoDB provider:

  • InsertEvent
  • ReplaceEvent
  • Serialize<T>

We are working on a WebApi Core 2.0 project with MSSQL database and we use MongoDB to save our application logs.

The point is that for saving complex entities with navigation properties we face the following error while saving the records to MongoDB: BsonSerializationException: Maximum serialization depth exceeded (does the object being serialized have a circular reference?) This happened because the ToBsonDocument() method can’t Ignore Reference Loopings and always return an exception.

We had a quick fix for this issue as followed. Changing this part in InsertEvent/ReplaceEnevt: var doc = auditEvent.ToBsonDocument(); to this: var doc = BsonDocument.Parse(JsonConvert.SerializeObject(auditEvent, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));

and also this part in Serialize<T>: return value.ToBsonDocument(typeof(object)); to this: return BsonDocument.Parse(JsonConvert.SerializeObject(value, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));

OR

You may add a setting to the UseMongoDB configuration so that Ignoring Reference Looping can be enabled or disabled.

Any suggestion or additional configuration would be appreciated.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
thepirat000commented, Nov 10, 2017

This is included from version 9.0.0.

Feel free to re-open the issue is you’re still having problems.

0reactions
HosseinZahedcommented, Nov 10, 2017

That would be great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's new in System.Text.Json in .NET 7
System.Text.Json determines how a given .NET type is meant to be serialized and deserialized by constructing a JSON contract for that type. The ......
Read more >
Suggestions on how to create a custom GeoJson serializer ...
I will be attempting to create a C# library to serialize objects to GeoJSON using Json.NET ( for serialization ) and GeoAPI.NET (...
Read more >
What's next for System.Text.Json? - .NET Blog
Learn about the new performance, reliaility and easy adoption that has been made with System.Text.Json, and what's going to come next.
Read more >
JSON.NET with SIMPL# : r/crestron
Hi Guys, I want to use JSON to store some configuration on Series 3 Processor's NVRAM file. I looked at other posts and...
Read more >
How to Convert XML to JSON In C# Using Json.NET
Converting XML to JSON data that can be loaded into Couchbase Server can be accomplished. Learn how to convert XML to JSON in...
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