Open Anthony-Breneliere opened 5 years ago
Json.NET's implementation of self-referencing loop detection depends on the object.Equals()
implementations of the underlying objects. For details see:
If the implementations of object.Equals()
for mocked objects differ between .Net Core 2.2 and
.NET Framework 4.72, you'll get different results for reference loop detection.
Using your own equality comparer on both frameworks, e.g. ObjectReferenceEqualityComparer<object>
from IEqualityComparer<T>
that uses ReferenceEquals, may make the two frameworks behave consistently.
Also, did you see How to mock (with Moq) an interface that is serialized by Newtonsoft.json?? The error looks to be identical.
I have got a loop referencing exception with .Net Core 2.2 but not Framework .NET 4.72, when serializing mocked objects with moq. Shouldn't the behavior be the same ? Here is the code to reproduce the exception:
Result: Newtonsoft.Json.JsonSerializationException: 'Self referencing loop detected for property 'Object' with type 'Castle.Proxies.IActionProxy'. Path 'Mock'.'
With .Net Framework the object actionMock.Object is properly serialized.
Moq is 4.10.1 and Newtonsoft.Json 12.0.2