473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

DefaultValue Attribute breaks XmlSerializer

I have a boolean property that I want to serialize to disk using XmlSerializer.

I noticed that if the property includes the attribute "DefaultValue(true)"
or "DefaultValue(false)" that the property will not serialilze to an XML
file. If the attribute is removed the serialization occurs just fine.

Is there a way around this bug? This behavior seems to work with any type
of property.

--
-----------
Thanks,
Steve
Oct 6 '06 #1
4 5311
Do you have a code sample here? I am pretty sure that I have used
[XmlAttribute, DefaultValue(false)] (to abbreviate the xml fragment)
and AFAIK it worked just fine. The only related thing I am aware of is
a known bug in WSE3 relating to [XmlAttribute] on byte[] properties.

Also - is this using XmlSerializer directly, or is it during usage in a
web-service? If the latter, then you should also clarify the specifics:
vanilla SOAP? WSE? (and if WSE, which version)

Marc

Oct 6 '06 #2
Futher to my previous answer, what do you mean "will not serialize"?
As, no, by definition if you have DefaultValue(false), and the value
*is* false, then it *won't* go into the file. This is the expected
behaviour, and is similar to the way the forms designer doesn't write
code for properties you haven't changed.

If you don't want this behaviour, then either don't specify a
DefaultValue, else perform the serialization manually using
IXmlSerializable (IIRC; don't have VS to hand).

Marc

Oct 6 '06 #3
Thank you. I didn't realize that if the "default value assigned in the init"
and the "DefaultValue(...)" - if the same - would not write the value out. I
just verified in my sample code and your statements are correct. Thank you.
Where did you learn that the behavior (when they are the same) is NOT to
write out the value?
--
-----------
Thanks,
Steve
"Marc Gravell" wrote:
Futher to my previous answer, what do you mean "will not serialize"?
As, no, by definition if you have DefaultValue(false), and the value
*is* false, then it *won't* go into the file. This is the expected
behaviour, and is similar to the way the forms designer doesn't write
code for properties you haven't changed.

If you don't want this behaviour, then either don't specify a
DefaultValue, else perform the serialization manually using
IXmlSerializable (IIRC; don't have VS to hand).

Marc

Oct 6 '06 #4
It is hinted at in the following two articles, but I can't (without a
search) find fuller mention:

http://msdn.microsoft.com/library/de...ialization.asp
http://msdn.microsoft.com/library/de...classtopic.asp

Marc

Oct 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Craig Schneider | last post by:
// Is there any way to override the XML Serialization of the following SimpleClass // to turn off the DefaultValue of a boolean? Sure, I can override the DefaultValue from // true to false, but...
4
by: Justine | last post by:
Hi All, I would like to know where & when exactly we would have a need for attributes. A realistic example. Thanz in Advance, Justine
5
by: schneider | last post by:
Hello, Have an issue with a property using the DefaultValue(True) attribute. Imports System.ComponentModel Public Class Class1 Private m_testValue As Boolean
2
by: tinyabs | last post by:
Hi, How do it set the default value of PopupSize? public Size PopupSize {
2
by: Rasmus Kromann-Larsen | last post by:
Hello, I'm currently playing around with the XmlSerializer to replace my old handmade Xml parsing code, but am having a few small issues with default values and derived classes. Say we have...
6
by: Peter Hartlén | last post by:
Hi! What's the correct syntax for the default value design time attribute, using classdiagram view and Custom Attributes dialog. For a boolean: DefaultValue(true) DefaultValue("true")...
10
by: Henrik Dahl | last post by:
Hello! I have an xml schema which has a date typed attribute. I have used xsd.exe to create a class library for XmlSerializer. The result of XmlSerializer.Serialize(...) should be passed as the...
3
by: Johnny Jörgensen | last post by:
Does anybody know how to correctly specify the defaultvalue attribute for a property whose type is an enum. Example: Public Enum TestValues Value1=1 Value2=2 End Enum
5
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Prior to C# 3.0, I would typically define a property of a custom user control with pattern A: === PATTERN A ========== private bool myBool = true; public bool MyBool { get { return myBool; }...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.