StackOverflowException

Mar 24, 2014 at 9:30 PM
I put a debug print in v1.3.1
public object MemberWrapper.GetValue(object obj){}
and got:
_"obj" {RfModelling.RfMaterialsVM}
"obj" {RfModelling.RfMaterial}
"obj" {RfModelling.ModelManipulation}
"obj" {0;0;0}
"obj" {0;0;0}
"obj" {0;0;0}
"obj" {0;0;0}
"obj" {0;0;0}
"obj" {RfModelling.ModelManipulation}
"obj" {RfModelling.ModelManipulation}
"obj" {1;1;1}
"obj" {1;1;1}
"obj" {1;1;1}
"obj" {1;1;1}
"obj" {1;1;1}
"obj" {RfModelling.ModelManipulation}
"obj" {0;0;0}
"obj" {0;0;0}
"obj" {0;0;0}
"obj" {0;0;0}
"obj" {0;0;0}
"obj" {RfModelling.ModelManipulation}
"obj" {System.Windows.DependencyObjectType}
"obj" {System.Windows.DependencyObjectType}
"obj" {Name = "ModelManipulation" FullName = "RfModelling.ModelManipulation"}
_____"obj" {RfModelling.exe}
"obj" {RfModelling.exe}
"obj" {RfModelling.exe}
"obj" {RfModelling.exe}
"obj" {RfModelling.exe}
"obj" {RfModelling.exe}
"obj" {RfModelling.exe}
"obj" {RfModelling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
"obj" {RfModelling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
"obj" {RfModelling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
"obj" {Void Main()}
"obj" {Void Main()}
"obj" {Name = "App" FullName = "RfModelling.App"}
"obj" {RfModelling.exe}


..... the part that is italicized repeated until the exception occurred.
I hope some of this is useful-if there is any other debug info that might be useful, let me know. The error still occurs if ModelManipulation is marked non-serialised. But it looks like it is getting a lot further than last time:-)
Coordinator
May 18, 2014 at 9:03 AM
I added a workaround for this issue in version 2.13 which is just released. The problem for this particular class is that the class Matrix has a calculated property called Inverse which also returns another instance of Matrix. The returned Matrix also has an Inverse and hence there's a cycle which leads to StackOverflowException

You can find a simpler example in the SampleClasses/SelfReferencingObjects/CalculatedPropertiesCanCauseInfiniteLoop.cs of the source code.

Calculated properties are usually getter (readonly) properties only. Therefore I added an option to the set of serialization options that prevents serializing readonly properties if set. Example:
var ser = new YAXSerializer(typeof(Matrix), YAXSerializationOptions.DontSerializePropertiesWithNoSetter);
There's another option added in version 2.13 which is called YAXSerializer.MaxRecursion property. Its default value is 300 (which is still a lot). But it prevents infinite loops/recursions in the serialization process.