Saturday, July 13, 2019

Self referencing loop detected for property 'Object' with type 'Castle.Proxies.IServiceContextProxy

When writing unit tests using Moq objects I occasionally get this error:
 Message="Self referencing loop detected for property 'Object' with type 'Castle.Proxies.IServiceContextProxy..."

It happens when JSON is trying to serialize an object that it thinks has a pointer to itself and could create an infinite loop - although in your code it may not be infinite, but JSON doesn't know that.  It's just trying to protect you.

 One way to fix this is to replace the Mock object with real fake object.


No comments: