Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do you stop Events being Serialized?

17 views
Skip to first unread message

Neal Andrews

unread,
Oct 15, 2003, 10:57:21 AM10/15/03
to
Hi All,

Does anyone know how to stop Events from being serialized in a class that
uses the <Serializable()> attribute?
I have tried using the <NonSerialized()> attribute but for some bizarre
reason, it is not allowed on events.
I am using VS 2003, if that makes any difference. The only thing I can think
of is to wrap all the events in a separate class and then not to mark the
class as Serializable.

TIA
Regards
Neal


Tom Spink

unread,
Oct 15, 2003, 11:58:30 AM10/15/03
to
Hi Neal, may I ask what the problem is with events being serialized?

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations


"Neal Andrews" <neal@NOSPAN_ALIAS.com> wrote in message
news:e8mX8zyk...@TK2MSFTNGP12.phx.gbl...

Neal Andrews

unread,
Oct 15, 2003, 12:44:04 PM10/15/03
to
Hi Tom,

I have a lot Business objects that need to be serialized across the network.
These objects each have a set of events. However when the Business objects
get serialized it also serialize's the the objects attached to the events. I
need a way to stop the objects attached to the events from being serialized.
I have just seen some C# code that uses the [field: NonSerialized] attribute
so that events do not get serialized. So there must be an equivalent
attribute in VB.NET, but I cannot seam to find it anyware.

Regards
Neal


"Tom Spink" <thomas...@ntlworld.com> wrote in message
news:uYnBhUzk...@TK2MSFTNGP10.phx.gbl...

Richard A. Lowe

unread,
Oct 15, 2003, 2:06:55 PM10/15/03
to
With this (somewhat odd) attribute syntax:

[field: NonSerialized]
public event EventHandler SomethingHappens;

HTH,
Richard

"Neal Andrews" <neal@NOSPAN_ALIAS.com> wrote in message news:<e8mX8zyk...@TK2MSFTNGP12.phx.gbl>...

Jay B. Harlow [MVP - Outlook]

unread,
Oct 15, 2003, 2:08:10 PM10/15/03
to
Neal,
Unfortunately VB.NET does not support the NonSerialized attribute on events
(VB.NET does not have a Field Attribute Modifier, as shown in your other
post.).

The three methods I know of are:
1. Define your events in a C# base class that defines the event as being not
serializable (via [field: NonSerializable] or event procedures).
2. Implement the ISerializable interface and serialize only actual fields.
3. Create a SerializationSurrogate object that only serializes the actual
fields.

For details on the third method see the "Possible Solution to Serializing
Event Handlers in VB" thread from 10 Oct 2003 in the
microsoft.public.dotnet.distributed_apps &
microsoft.public.dotnet.framework.remoting newsgroups.

Because I need ISerializable for version control, I'm using the second
method.

Hope this helps
Jay

"Neal Andrews" <neal@NOSPAN_ALIAS.com> wrote in message
news:e8mX8zyk...@TK2MSFTNGP12.phx.gbl...

Jay B. Harlow [MVP - Outlook]

unread,
Oct 15, 2003, 2:10:19 PM10/15/03
to
Richard,
Not supported in current versions of VB.NET!

Unless of course you are saying in a C# base class.

Hope this helps
Jay

"Richard A. Lowe" <cha...@yahoo.com> wrote in message
news:2a3d9959.03101...@posting.google.com...

Neal Andrews

unread,
Oct 15, 2003, 3:19:00 PM10/15/03
to
Thanks a lot, At least I can stop looking for something that does not exist.
I'll look into those suggestions you made.

Regards
Neal

"Jay B. Harlow [MVP - Outlook]" <Jay_H...@email.msn.com> wrote in message
news:%23DTzOd0...@tk2msftngp13.phx.gbl...

Peter Huang [MSFT]

unread,
Oct 16, 2003, 2:28:47 AM10/16/03
to
Hi Neal,

As for Jay's second suggestion, you may try to take a look at the link
below.
ISerializable Interface
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemRuntimeSeriali
zationISerializableClassTopic.asp

Hope this helps.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
>From: "Neal Andrews" <neal@NOSPAN_ALIAS.com>
>References: <e8mX8zyk...@TK2MSFTNGP12.phx.gbl>
<#DTzOd0k...@tk2msftngp13.phx.gbl>
>Subject: Re: How do you stop Events being Serialized?
>Date: Wed, 15 Oct 2003 20:19:00 +0100
>Lines: 57
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <eZS4PG1k...@TK2MSFTNGP10.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: modem-636.lemur.dialup.pol.co.uk 217.135.130.124
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147002
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

0 new messages