Serialization of BOs that contain XElements

Serialization of BOs that contain XElements

Old forum URL: forums.lhotka.net/forums/t/7497.aspx


OpticTygre posted on Sunday, August 23, 2009

Hi all. I have some BOs that inherit from my base BOs, which in turn inherit from BusinessBase and BusinessListBase. Each of my base BOs - let's call them MyBusinessBase and MyBusinessListBase contain 2 private member variables of type XElement.

All of my classes are marked as Serializable, and each of the private variables of type XElement have been marked as NonSerialized.

Instantiating my BO works fine, however, when I attempt to set the datasource of my bindingsource (WinForms), I receive the error:

Type 'System.Xml.Linq.XElement' in Assembly 'System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

This error is thrown in the CSLA BinaryFormatterWrapper class when the serialize method is called.

Any clue what's going on here? Thanks!

JonnyBee replied on Sunday, August 23, 2009

Hi,

You must also mark these fields as [NotUndoable]. When BeginEdit is called the n-level undo code will make a snapshot of you BO graph and that is when you get this error.

[NotUndoable] must also be applied to fields that may point back into top levels in you structure (likely to cause recusive calls in serializing and give "out of memory" exception).

/jonnybee

OpticTygre replied on Monday, August 24, 2009

Thanks, Jonny. Makes perfect sense to me. With that, and a little code cleanup, it seems to have solved the issue.

Copyright (c) Marimer LLC