Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Create a Non-Serialized Event in 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
timw - 27 Mar 2006 14:06 GMT
I am having trouble creating an event that is non-serializable in 2.0.  In
1.1, I would have just put the [field:NonSerialized] Attribute on the event
as this is the MS-endorsed hack for making it non-serializable.



What I'm trying to do is the following:

public delegate void Notification(object notificationObject);

public interface INotification

{

[field:NonSerialized]

event Notification NotificationEvent;

}



Like I said, this worked perfectly fine in 1.1, but in 2.0 I get the
following warning:

warning CS0657: 'field' is not a valid attribute location for this
declaration. Valid attribute locations for this declaration are 'method,
event'. All attributes in this block will be ignored.

If I change field to method or event, the Attribute barfs saying:

Attribute 'NonSerialized' is not valid on this declaration type. It is valid
on 'field' declarations only.

Are there other ways to do this with an EventHandler on an interface?  
Mattias Sjögren - 27 Mar 2006 17:42 GMT
>Are there other ways to do this with an EventHandler on an interface?  

Why do you want to put it on the interface method? Interfaces don't
have any data to serialize anyway. Put the attribute on the event in
the implementing class instead.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

timw - 27 Mar 2006 18:32 GMT
That is correct, interfaces do not have any data in them.  All of the classes
behind the interface in this case should never have the event serialized.  

I had thought that I tried that scenario, but did not.
Thanks.

Alternatively, I could have used add/remove accessors and stored the
eventhandler list myself, but I did not want to write that for all of my
events.  

I have yet to find any documentation of this breaking change, or perhaps it
was a warning that was never caught in 1.1?

> >Are there other ways to do this with an EventHandler on an interface?  
>
[quoted text clipped - 3 lines]
>
> Mattias

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.