Questions tagged [nonserializedattribute]

16 questions
19
votes
5 answers

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?
skb
  • 30,624
  • 33
  • 94
  • 146
11
votes
5 answers

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…
Tim W.
  • 834
  • 1
  • 9
  • 18
6
votes
1 answer

How to specify a NonSerialized field with public accessors for XML Serialization

How do you specify a NonSerialized field with public accessors for XML Serialization? [NonSerialized] public String _fooBar; //Declaring the property here will serialize the _fooBar field public String FooBar { get { return _fooBar; } set {…
MPelletier
  • 16,256
  • 15
  • 86
  • 137
6
votes
3 answers

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…
Stefan Monov
  • 11,332
  • 10
  • 63
  • 120
6
votes
2 answers

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 but Transcender says I am wrong. I…
IbrarMumtaz
  • 4,235
  • 7
  • 44
  • 63
4
votes
2 answers

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…
ck.
  • 1,056
  • 1
  • 14
  • 25
3
votes
2 answers

How do you serialize an unmodifiable class that contains an interface?

I am trying to serialize an object that contains an interface. However, interfaces cannot be serialized. Normally, I would use something like the NonSerialized tag, but I cannot figure out how to apply this attribute to a class that I cannot modify,…
2
votes
0 answers

FindBugs non-transient non-serlizable error for XMLGregorianCalendar and class relies on internal api classes

I'm using FindBugs 2.0.2. While validating my project with findbugs i'm getting following errors: In class com.vo.Account Field com.vo.Account.startDat Actual type javax.xml.datatype.XMLGregorianCalendar In Account.java Class com.vo.Account defines…
nag
  • 31
  • 1
  • 4
2
votes
1 answer

NonSerialized for multiple properties

Do i have to put [NonSerialized] for each property of a class? [NonSerialized] public Cell Owner; [NonSerialized] public double Time
maxc900
  • 69
  • 10
0
votes
0 answers

how to pass the handle restart function to quizresult screen without using route causing sinice is non-sereliazable warnings

//here is part of code sin Quizscreen where im passing this restart quiz function that i need to acess in quiz result scree. const handleRestart = () => { setSelectedAnswer(null); setCurrentQuestion(0); setShowExplanation(false); …
0
votes
0 answers

How to get value of HTML dt/dd item with Playwright.js?

How can I get the content of iframe which has a document inside using playwright script? At the moment I am using framelocator const iframe = page.frameLocator('#CustomPartyNavAnchor15'); const contentFrame = await…
0
votes
0 answers

When should I use NonSerializedAttribute in C#?

I am trying to write a class in C# with [Serializable()] mark. Then I noticed that there are some situations the NonSerializedAttribute mark is needed. The event delegate could not be serialized Constant member, such as NonSerialized attribute on a…
JimmyHu
  • 403
  • 1
  • 8
  • 20
0
votes
2 answers

Workflow SerializationException because of complex object

I got the following exception: System.Workflow.Runtime.Hosting.PersistenceException: Type ‘Microsoft.SharePoint.SPWeb’ in Assembly ‘Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ is not marked as…
0
votes
1 answer

Error at server shut down & start up org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFile

I am on a Struts 1 application! My application show error when ever its Shut down & start up. I find two different but related error at both shut & start of my server. The shut down error goes like below WARNING: Cannot serialize session…
Das
  • 87
  • 1
  • 10
0
votes
1 answer

How can I have a required and nonSerialized attribute in my model

In my Model I have things like that : [...] public string PasswordConfirm { get; set; } public string Captcha { get; set; } [...] I would like that these two attributes are required but not serializable I tried tu use [required]…
1
2