473,386 Members | 1,827 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,386 software developers and data experts.

Framework bug with XmlArray + XmlArrayItem + IsNullable?

Hello all,

The XML file generated by the attached code correctly generates the
<Items xsi:nil="true"/> element when serializing, but when
deserializing, the Items field becomes an zero-sized array, while
instead I want to have a null reference.

However, when removing the XmlArrayItem attribute, the code works
fine.

Either I don't understand the behaviour of these attributes, or this
is a bug in the framework (I'm using the 1.1)

Any idea how to solve this one?

Thanks,
Peter

using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Diagnostics;

namespace NullTest
{
public class Container
{
[XmlArray(IsNullable=true)]
[XmlArrayItem(typeof(string), IsNullable=true)]
public ArrayList Items = null;

[STAThread]
static void Main(string[] args)
{
Container container = new Container();

XmlSerializer serializer = new
XmlSerializer(typeof(Container));

using( StreamWriter writer = File.CreateText(@"_Test.xml") )
{
serializer.Serialize(writer, container);
}

using( StreamReader reader = File.OpenText(@"_Test.xml") )
{
container = (Container)serializer.Deserialize(reader);
Debug.Assert(container.Items==null);
}
}
}
}
Nov 12 '05 #1
0 2539

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

Similar topics

0
by: Ravindra | last post by:
Well I installed the framework provided by microsoft , the problem is I am able to activate the smart tag in the doc file but when I Click on the Show Detils option in the information bridge the...
0
by: Chatterbox | last post by:
Hello all, The XML file generated by the attached code correctly generates the <Items xsi:nil="true"/> element when serializing, but when deserializing, the Items field becomes an zero-sized...
0
by: Q. John Chen | last post by:
I am using to avoid null field being created into Xml when Serializing. But how can this feature being used for an integer or DateTime? Thanks JOHN
2
by: Wilco | last post by:
I'm trying to serialize a collection, which is the root element, however the items in the collection contain derived classes, and thus give an error without XmlArrayItem attributes. However I can't...
1
by: teddysnips | last post by:
<NEWBIE ALERT> Owing to staff lossage, I've been forced to take over maintenance and upgrade of a completely undocumented web service (VS 2003, VB.NET). I've been asked to amend a Public...
1
by: SP | last post by:
I have a web service application which uses 3rd party assemblies. I recently upgraded my solution to use .NET Framework 2.0 instead of .NET Framework 1.1. The 3rd party assemblies that I refer are...
0
by: Ross Presser | last post by:
I want to deserialize this XML: <Header> <Sender> <Credential domain="DUNS"> <Identity>12345</Identity> <sharedSecret>coyote</sharedSecret> </Credential> <Credential domain="email">...
0
by: | last post by:
Hi I'm currently having trouble serializing an object to Xml, in the format I need. Below is the object definition. ------------------------------- public class Folders {
0
by: cfatulescu | last post by:
Hello, i'm trying to reproduce a method using Reflection.Emit, everything is going well except one small thing, without all my job is done for nothing. I can not reproduce the keyword...
2
by: barnum | last post by:
Hi, does anyone know if I can have an XmlArray with two unrelated XmlArrayItem, i.e. where the items are not child-parent related? I tried this, but I get an exception when creating the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.