views:

37

answers:

1

I have two projects: A/B. Project A is the project that contains all of the winforms which are bound to objbects in B (logic items)

A has an object of type A.Form

B has objects of type B.Serializer B.Logic

Now, A has a reference to B (but B does not have a reference to A) and A.Form contains a member variable of type B.Logic. At some point, when all of the data is stored in B.Logic I try to save this object to disk by calling B.Serializer(B.Logic).

At this point I get an error when serializing saying that A.From is not marked as serializable.

But the project B has NO reference to A at ALL and even if it did SOMEHOW have a member referencing A.Form, it shouldn't even compile.

+1  A: 

The usual culprit here is things like events (in B.Logic), or other back-references to external objects. You can mark fields as not for serialization:

    [NonSerialized]
    private SomeType foo;

or with field-like events:

    [field: NonSerialized]
    public event EventHandler Bar;

As an aside - from the description, I assume that you are using BinaryFormatter; personally, I have reservations about this - it is very brittle. I'd suggest something non-implementation-specific; XmlSerializer, protobuf-net, Json.NET, etc.

Marc Gravell
Yes, Jon skeet forwarded me to protobuf-net and I'd like to implement it but the time constraints are a bit prohibitive for at least another month at work. I'll see if it's events causing the problem and get back to you.
SnOrfus
You sir, are an eagle amongst turkeys. Thank you. It was indeed an event that was being serialized.
SnOrfus