Problem with XMLSerializer in .NET 2.0

We use the XMLSerializer to serialize a class hierarchy. This works fine in .NET 1.1 but in .NET 2.0 beta 2 I am getting the following error message:

"If one class in the class hierarchy uses explicit sequencing feature (Order), then its base class and all derived classes have to do the same."

This message is actually from the most inner exception. The 15 or so nested "outer" exceptions reported the following.

"System.InvalidOperationException: There was an error reflecting type 'mytype'

This error occurs on the call

XmlSerializer oSerializer =newXmlSerializer(oData.GetType());

where oData is object I am serializing.

I can't find any reference to this error message and I have no idea what "explicit sequencing feature (Order)" means.

Any help would be appreciated.

Thanks,
Tim

[942 byte] By [tim2005] at [2008-1-25]
# 1
I have the same issue, however it appears only on Itanium 2 platform. When using .NET 2.0 on a virtual machine everything is working.
Even worse - I have two classes, that differ only in naming and field order and one of them serializes as expected, on of them fails with the above error.

Vladimir

VladimirTchalkovMVP at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 2

I was informed it was a know bug in .NET 2.0 beta 2. It has something to do with the "Order" property and the work around is to add the "Order" property to all element members in the class hierarchy you are serializing which is rather nasty. Since our hierachy was fairly complex I gave up before I was able to make that work for me.

I suspect the difference between the machines might be that you have different versions of the .NET Framework 2.0.

Tim

tim2005 at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 3
Tim,

I am running into the same issue. You alluded to an "Order" property work around. Do you have any specifics on what the work around entails? Thanks in advance.

Tony

TonyHarris at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 5

This has now been fixed.

EugeneOsovetsky at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 6

Ok so now that it's fixed, can you please tell us how we go about updating our current Beta 2 framework so we can continue with development? This has me at a dead standstill with code that ran perfect on Beta1.

TundraNerd at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 7
Well it looks like the bug should be fixed in the latest Whidbey bits so hopefully you won't need to do this and I would recommend you go with that if at all possible.

If you can't move to the latest whidbey for some reason then here's a bit more detail from what I can remember.

The "Order" property is not really documented. The closest thing I found is here

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRuntimeRemotingMetadataSoapFieldAttributeClassOrderTopic.asp

It appears to allow you to specify the order that the public fields and properties of your class are written out to the XML for SOAP encoding in this case. It's a bit hoaky since you have to specify the order using an absolute number and you must specify it for each serialized member in the class. If you use it in a derived class you must also use it in the base class meaning you have to keep count.

From this I inferred, given the terse workaround description, that you can also use this property in the XmlElement attribute. So in C# it is probably.

[XmlElement(ElementName= "FieldName1", Order=1)]
public string someField1;

[XmlElement(ElementName= "FieldName2", Order=2)]
public string someField2;

If I rememeber correctly this seemed to work but I was not able to confirm that it fixed the problem. Due to time constraints I gave up and we worked around it by not using the beta.

I should note that the bug was not universal. I created a class structure that serialized fine in beta 2. I never found out what triggered the bug but it probably occured if the class was derived from a .NET framework class (the collection classes fex)

tim2005 at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...

.NET Development

Site Classified