Re: A problem with object graph in BinaryFormatter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc Gravell

    Re: A problem with object graph in BinaryFormatter

    Well, there are various memory profilers that might help, but first;
    note that BinaryFormatter works on fields, not properties - so it
    might be that you have a private field somewhere that is the offender.
    You can mark such fields with NonSerializedAt tribute if you don't want/
    need it to be serialized.

    The most common cause (in my experience) of this is events; people
    tend to overlook events, and it is not obvious what subscribers might
    be attached to events. Fortunately you can also apply this attribute
    to delegate fields, even for compiler-provided event delegates:

    [field: NonSerialized]
    public event EventHandler Foo;

    or for explicit event implementations :

    [NonSerialized]
    private EventHandler foo;
    public event EventHandler Foo
    {
    add { foo += value; }
    remove { foo -= value; }
    }

    Marc
Working...