You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
using Moq;
using System;
using System.Runtime.Serialization;
namespace ConsoleApp1
{
public interface IAction
{
string Description { get; }
object Argument { get; }
}
class Program
{
static void Main(string[] args)
{
var actionMock = new Mock<IAction>().SetupAllProperties();
// actionMock.As<ISerializable>();
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(actionMock.Object));
}
}
}
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
The text was updated successfully, but these errors were encountered:
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.
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
The text was updated successfully, but these errors were encountered: