A problem with object graph in BinaryFormatter

  • Thread starter Thread starter Behzad
  • Start date Start date
B

Behzad

hi all,

I have a problem with binaryformatter class.Wish you could help me.

suppose there is an object with lots of properties each referencing to
an object.each object, itself can reference to some other complex type
all of each are my own classes not .net classes.

Now after calling the Serialize method, an exception thrown which
says:

Type "xxx classs" in Assembly 'xxx assembly, Version=1.0.3137.28396,
Culture=neutral, PublicKeyToken=null' is not marked as serializable.

what i am searching is the property to which the exception referes.i
have searched my code and did not find the reference the exception
says.So i came to conclusion if there was an object graph inspector i
could find the problem.I googled but did not find any.Could you please
help me if you know one?

Thanks in advance
Sedighzadeh
 
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 NonSerializedAttribute 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
 
You could also check out manual serialization.
Then you have complete control over what gets serialized - this would help
you to narrow it down.

Is the class mentioned in the error message one of yours?
If it is the answer might be as as simple as adding [Serializable] to your
class.

HTH,

Adam
========
 
hi, thanks,

ironically, error says 'the xx class has not marked as ... ' and i
have serialized one of xx properties!!! i searched through all classes
but i did not find any thing, as this ( my search) is correct because
in my design xx is an actor and one its classes which is data has been
serialized.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top