nonserializedattribute

Why do I need "field:" in my attribute declaration "[field:NonSerialized]"?

I can't find "field" listed as a C# keyword anywhere. Does anyone know the background on this? ...

Why can't the 'NonSerialized' attribute be used at the class level? How to prevent serialization of a class?

I have a data object that is deep-cloned using a binary serialization. This data object supports property changed events, for example, PriceChanged. Let's say I attached a handler to PriceChanged. When the code attempts to serialize PriceChanged, it throws an exception that the handler isn't marked as serializable. My alternatives: I...

What's the difference between the [OptionalField] and [NonSerialized]

I came across this question on transcender: What should you apply to a field if its value is not required during deserialization? Me = [NonSerialized], ANSWER = [OptionalField] My gut reaction was NonSerialised, I have no idea why but in the space of 5 seconds thats what I thought but to my surprise, Transcender says I am wrong. OK fa...

Cookie problem in classes

Hi there, I want use cookie in my web project. I must serialize my classes. Although my code can seralize and create cookie for my some classes, it cant create cookie for serializable my class which has NonSerialized fields. This is my seralize and cookie code : public static bool f_SetCookie(string _sCookieName, object _oCookieValue, ...

Benefits of [NonSerialized] when [Serializable] is not used.

I'm looking through some existing code in a project I'm working on, and I found a class that is implemented as: public class ThingOne { private int A; private int B; [NonSerialized] private System.Timers.Timer timer1; } Shouldn't it look more like this? [Serializable] public class ThingOne { private int A; ...

Why doesn't [NonSerialized] work on autoimplemented properties?

[Serializable] class MyClass { [NonSerialized] int Foo { get; set; } // error [NonSerialized] int bar; // ok } Why is this disallowed? I know about the workarounds such as implementing ISerializable switching to XmlSerializer/XmlIgnore switching to a manually-implemented property The question is specifically why is [NonSer...