Crispin,
I've also come accross this limitation in VB. In the current version, it is
not possible to specify the <NonSerialized> attribute to an event in VB (and
thus prevent objects attached through event handlers being serialized as
part of the object graph).
It may appear in the next version (can anyone confirm this?). Until then,
here are a few workarounds that I've been using sucessfully:
1) Implement ISerializable in your class and do not add the events to the
serialization
2) Implement a class that implements ISerializationSurrogate and use this to
control serialization of your objects.
3) Disconnect event handlers before serializing
4) Implement your events in a C# base class and mark them with the
[NonSerialized] attribute.
The solution that I've found easiest to implement and easiest to use is to
create a base class that Implements ISerializable and uses reflection to get
the fields to be serialized (and ignores the fields and events that
shouldn't be serialized). You then inherit from this class for all objects
that need serialized.
Let me know if you want code for this and I'll dig it out and post it here
for you.
Hope this helps,
Trev.
Crispin Horsfield said:
It's not useful to serialize events in a class that can be serialized
so in C# you can use the 'field' attribute to mark events as
'NonSerializable'.This is not available in VB. Does anyone know when
it might be?
TIA
Crispin Horsfield
Caz Limited, Bristol, UK
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---