I have a rules engine that uses Expression trees to run rules logic on a certain input and tells the user whether the object passes or fails the rules.
I have run into an issue where deserialzing an object to a custom type is producing different results than the same object passed directly without serialization.
var results = Rules.Run(myObject)
// results pass
MyType input = JsonConvert.DeserializeObject<MyType>(JsonConvert.SerializeObject(myObject));
var results = Rules.Run(input)
// results fail
The reason I noticed this is because I am building a WebApi. When I run a unit test on my function by passing myObject to the controller function, everything works fine, but when it comes in through a web request (hence running through the deserializer to convert from JSON) I get a failed result in my rules.
Stranger yet, the failure only occurs on one rule out out 5, the other rules all pass and all of them require reading the same values from the passed object.
I added JsonConvert.DeserializeObject(JsonConvert.SerializeObject(myObject)) to my unit test and it also fails after going through the deserialization.
Inspecting both the objects in the debugger shows them to have the exact same values.
What is going on here?