473,769 Members | 7,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you stop Events being Serialized?

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
7 3671
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.Reflecti on Master "

==== Converting to 2002 ====
Remove inline declarations
"Neal Andrews" <neal@NOSPAN_AL IAS.com> wrote in message
news:e8******** ******@TK2MSFTN GP12.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
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**********@n tlworld.com> wrote in message
news:uY******** ******@TK2MSFTN GP10.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.Reflecti on Master "

==== Converting to 2002 ====
Remove inline declarations
"Neal Andrews" <neal@NOSPAN_AL IAS.com> wrote in message
news:e8******** ******@TK2MSFTN GP12.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
With this (somewhat odd) attribute syntax:

[field: NonSerialized]
public event EventHandler SomethingHappen s;

HTH,
Richard

"Neal Andrews" <neal@NOSPAN_AL IAS.com> wrote in message news:<e8******* *******@TK2MSFT NGP12.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
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 SerializationSu rrogate 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.publi c.dotnet.distri buted_apps &
microsoft.publi c.dotnet.framew ork.remoting newsgroups.

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

Hope this helps
Jay

"Neal Andrews" <neal@NOSPAN_AL IAS.com> wrote in message
news:e8******** ******@TK2MSFTN GP12.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
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.goo gle.com...
With this (somewhat odd) attribute syntax:

[field: NonSerialized]
public event EventHandler SomethingHappen s;

HTH,
Richard

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

news:<e8******* *******@TK2MSFT NGP12.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
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********@ema il.msn.com> wrote in message
news:%2******** ********@tk2msf tngp13.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 SerializationSu rrogate 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.publi c.dotnet.distri buted_apps &
microsoft.publi c.dotnet.framew ork.remoting newsgroups.

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

Hope this helps
Jay

"Neal Andrews" <neal@NOSPAN_AL IAS.com> wrote in message
news:e8******** ******@TK2MSFTN GP12.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
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
zationISerializ ableClassTopic. 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_AL IAS.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.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: modem-636.lemur.dialu p.pol.co.uk 217.135.130.124
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:147002
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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********@ema il.msn.com> wrote in message
news:%2******* *********@tk2ms ftngp13.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 SerializationSu rrogate 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.publi c.dotnet.distri buted_apps &
microsoft.publi c.dotnet.framew ork.remoting newsgroups.

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

Hope this helps
Jay

"Neal Andrews" <neal@NOSPAN_AL IAS.com> wrote in message
news:e8******** ******@TK2MSFTN GP12.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1056
by: Jason | last post by:
I have a class which inherits from CollectionBase. My version adds events to notify client whenever items are added or removed from the collection. I wrote it in VB.NET. If I have a class which creates an instance of the collection and adds handlers to the events it raises, and then try to serialize the collection I get an error about the client not being marked as serialized. This is because of the reference the collection maintains...
3
16333
by: mikeb | last post by:
I have a class (settings, etc.) which is derived from CollectionBase and contains a number of fields and a few events. When I create an instance of this class in my app, and serialize it, it works. If I add an event handler in my app (for one of the events in my settings class), I get an exception that my app class is not marked as Serializable. If I mark the app class as Serializible, I get an exception that Type System.Windows.Forms.Form...
5
15183
by: Neil Norfolk | last post by:
I am using C# in Visual Studio 2003. I would like to serialize a class that contains, amongst other things, public delegate void DocumentsPreferencesChange(object env, Documents e); public event DocumentsPreferencesChange OnDocumentsPreferencesChange; However, as it stands, the classes containing any methods/delegates that have been added to OnDocumentsPreferencesChange also have to be serializable: this I do not want. I do not actually...
7
4584
by: Denise | last post by:
I just realized the DataTable_RowChanging events were firing when I called Fill method of the DataAdapter! It fires TWICE for each row loaded. I thought these were only supposed to be called when data was actually being edited. I am using bound textbox controls on the form. Could that have anything to do with it? Does anyone know how to stop the RowChanging events from firing? Thanks!
0
895
by: Jason | last post by:
I have a class which inherits from CollectionBase. My version adds events to notify client whenever items are added or removed from the collection. I wrote it in VB.NET. If I have a class which creates an instance of the collection and adds handlers to the events it raises, and then try to serialize the collection I get an error about the client not being marked as serialized. This is because of the reference the collection maintains...
2
4115
by: Timo | last post by:
When I use XML serialization to serialize MyCustomObjectCollection, all of the public fields of MyCustomObject are being serialized, even those I've given the <NonSerialized()> attribute. <Serializable()> Public Class MyCustomObject Public FieldID As String Public ParentId As String Public ItemId As String
1
2731
by: AlexZh | last post by:
Hi, I'd like to stop command line build by one project build failed. To do that I've created simple AddIn (see code below), that works fine for IDE and does not work for command line. In the AddIn I have only two non-trivial methods: In OnConnection I add my event handler to OnBuildProjConfigDone, and in the event handler I executed Build.Cancel. In IDE - no problem. When I execute I see that AddIn works and Build.Cancel is called but...
0
3284
by: =?Utf-8?B?am1hZ2FyYW0=?= | last post by:
My program needs to do X when someone 'starts using' their Windows user account, and it should do Y when they 'stop using' their Windows user account. By 'starts using' I mean they log on, unlock the desktop, resume from hibernate/sleep, or resume a session that was paused via Switch User. By 'stop using' I mean they lock the desktop, initiate a hibernate/sleep , or choose Switch User while logged on. For context, the program is a parental...
2
1821
by: Rigor69 | last post by:
Hi There. I'm working on a application with a multiple level object structure. Object type "Cproject" holds an arraylist of "Csystem". A "Csystem" contain custom events i listen for in "Cproject" When i add items to the lists of "Csystem" i also add eventhandlers for the above events. When the object structure is serialized to an xml-file, and then deserialized, my event handlers are lost, since at the deserialization of "Cproject",...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.