Possible bug in .Net framework?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Guys please post your comments to (e-mail address removed)

using System;
using System.Xml;
using System.IO;
using System.Xml.Serialization;

namespace ConsoleApplication1
{


[Serializable()]
public class tResponseGeneralInfo
{
public long ProfileNumber;

public bool ProfileNumberSpecified;

}

class Class1
{
[STAThread]
static void Main(string[] args)
{
tResponseGeneralInfo obj = new tResponseGeneralInfo();
obj.ProfileNumber = 23;

XmlDocument oXmlDoc = new XmlDocument();
oXmlDoc.Load(m_Serialize(obj));
}

private static MemoryStream m_Serialize(object obj)
{
try
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
System.IO.StreamWriter sw = new StreamWriter("C:\\test.txt");
serializer.Serialize(sw, obj);
ms.Position = 0;
sw.Close();
return ms;
}
catch(Exception ex)
{
throw ex;
}
}
}
}


Now ProfileNumber is missing, the funny party is when i change the variable
name ProfileNumberSpecified to something else it starts working


"<?xml version=\"1.0\"?><tResponseGeneralInfo
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><ProfileNumberSpecified>false</ProfileNumberSpecified></tResponseGeneralInfo>"
 
Rohit said:
Guys please post your comments to (e-mail address removed)

If you don't read this group, you don't get my reply.
public class tResponseGeneralInfo

Have you decided to find a way to name your classes that's guaranteed to
be unique in the world? :-)
XmlSerializer serializer = new XmlSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
System.IO.StreamWriter sw = new StreamWriter("C:\\test.txt");
serializer.Serialize(sw, obj);
ms.Position = 0;
sw.Close();
return ms;

What's with the memory stream? It isn't ever used, is it?



Oliver Sturm
 
Guys please post your comments to (e-mail address removed)
there is a trick to find the answers easily!

Menu: View => Current View => Group message by conversation
and
Menu: View => Current View => Show reply to my messages
 
Am sorry about the screw up, i copy pasted old code

---
XmlSerializer serializer = new XmlSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
serializer.Serialize(ms, obj);
ms.Position = 0;
return ms;
---

This is a snippet of code am using in my project, please replace the
class name etc which ever way you like it and please try to concentrate
on the problem am not concern about the best practise at the moment.

I am unable to understand why the XML serialization skips the
ProfileNumber. Any pointers please!!!???
 
I am unable to understand why the XML serialization skips the
ProfileNumber. Any pointers please!!!???

I gave it a go, but I'm sorry to say the only thing I found out is that I
can confirm your findings. I tried this is VS 2003 and VS 2005 beta 2,
with the same result.

The problem seems to be in the naming: as long as one of the fields' names
is a leading part of the other, the shorter one is left out. So this goes
for ProfileNumber and ProfileNumberSpecified, but you can work around by
calling one of the fields something completely different, or just
appending an 'X' to the ProfileNumber field name.

The fact that this happens in both framework versions seems to indicate it
might be on purpose - but I was unable to find any information about it
and I really can't imagine the purpose.

Maybe it would be a good idea to post this to the dotnet.xml group,
possibly there are some people reading there who have additional knowledge
about XML serialization.


Oliver Sturm
 
Back
Top