By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,674 Members | 1,459 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,674 IT Pros & Developers. It's quick & easy.

How do you stop Events being Serialized?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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:e8**************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #2

P: n/a
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" <th**********@ntlworld.com> wrote in message
news:uY**************@TK2MSFTNGP10.phx.gbl...
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:e8**************@TK2MSFTNGP12.phx.gbl...
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


Nov 20 '05 #3

P: n/a
With this (somewhat odd) attribute syntax:

[field: NonSerialized]
public event EventHandler SomethingHappens;

HTH,
Richard

"Neal Andrews" <neal@NOSPAN_ALIAS.com> wrote in message news:<e8**************@TK2MSFTNGP12.phx.gbl>...
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

Nov 20 '05 #4

P: n/a
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:e8**************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #5

P: n/a
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" <ch*****@yahoo.com> wrote in message
news:2a**************************@posting.google.c om...
With this (somewhat odd) attribute syntax:

[field: NonSerialized]
public event EventHandler SomethingHappens;

HTH,
Richard

"Neal Andrews" <neal@NOSPAN_ALIAS.com> wrote in message

news:<e8**************@TK2MSFTNGP12.phx.gbl>...
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

Nov 20 '05 #6

P: n/a
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]" <Ja********@email.msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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:e8**************@TK2MSFTNGP12.phx.gbl...
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


Nov 20 '05 #7

P: n/a
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...RuntimeSeriali
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: <e8**************@TK2MSFTNGP12.phx.gbl> <#D**************@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: <eZ**************@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!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147002
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

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]" <Ja********@email.msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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:e8**************@TK2MSFTNGP12.phx.gbl...
> 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 markthe > class as Serializable.
>
> TIA
> Regards
> Neal
>
>




Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.