I am using a method to serialize objects to xml.
this method is working fine to serialize most of the objects to Xml.
For one collection object, it is not doing so. The Collection and its
containing object are marked [Serilizable].
What could be the reasons for the object not getting serialize, and this is
what i get.
<?xml version="1.0"?>
<ArrayOfAllocatedTrade xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
<AllocatedTrade xsi:nil="true" />
</ArrayOfAllocatedTrade>
Allocated trade is an object with around 10-12 properties.
This is working fine for all other objects, sample right serialization,
<?xml version="1.0"?>
<CloseTradeInterface xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<BrokenRulesCollection />
<CloseTradeFilter>
<BrokenRulesCollection />
<CloseTradeDate>2006-12-28T14:59:09.2045251+05:30</CloseTradeDate>
<Funds>
<Fund>
<BrokenRulesCollection />
<ID>1</ID>
<ShortName>FundA</ShortName>
<FullName />
</Fund>
</Funds>
<DataSourceNameID>
<BrokenRulesCollection />
<ID>1</ID>
<FullName />
<ShortName />
</DataSourceNameID>
<AUECListValues>
<AUEC>
<BrokenRulesCollection />
<AUECID>1</AUECID>
<AUECName>Equity\US\NASDAQ\USD</AUECName>
</AUEC>
<AUEC>
<BrokenRulesCollection />
<AUECID>11</AUECID>
<AUECName>Equity\US\ARCA\USD</AUECName>
</AUEC>
</AUECListValues>
<DefaultMethodology>0</DefaultMethodology>
<Algorithm>1</Algorithm>
</CloseTradeFilter>
<NetPositions>
<Position>
<BrokenRulesCollection />
<ID>39f10d1f-a6f0-4dcc-9193-d1404a27babd</ID>
<ModifiedAt>2006-12-28T15:01:03.8640112+05:30</ModifiedAt>
<StartDate>2006-12-28T15:01:03.8484049+05:30</StartDate>
<ModifiedBy>0</ModifiedBy>
<Symbol>GOOG</Symbol>
<FundValue>
<BrokenRulesCollection />
<ID>1</ID>
<ShortName />
<FullName>FundA</FullName>
</FundValue>
<AveragePrice>27.4833333333333</AveragePrice>
<PositionType>Long</PositionType>
<AUECID>1</AUECID>
<OpenQty>5500</OpenQty>
<ClosedQty>5000</ClosedQty>
<GeneratedPNL>118149.7618333335</GeneratedPNL>
<PositionTaxLots>
<AllocatedTrade xsi:nil="true" />
</PositionTaxLots>
</Position>
</NetPositions>
</CloseTradeInterface>
The Serializable Attribute does not make a class serializable as XML.
Serialization encompasses far more than XML Serialization, and is, in fact,
simply defined as the conversion of objects into arrays of bytes that can be
serialized either binarily, or as text.
XML Serialization does not require the Serializable Attribute for
serialization. All you need is the System.Xml.Serialization.XmlSerializer
class to do this. There are, however, a number of attributes that help
control how objects are serialized as XML, and there are some rules
regarding what is and what is not serializable as XML (without any custom
serialization, that is - anything can be serialized as XML using custom
serialization).
According to the SDK, "XML serialization serializes only the public fields
and property values of an object into an XML stream. XML serialization does
not include type information....XML serialization does not convert methods,
indexers, private fields, or read-only properties (except read-only
collections)."
Here are a few helpful links on the topic:
Introducing XML Serialization
http://msdn2.microsoft.com/en-us/library/182eeyhh.aspx
System.Xml.Serialization Namespace
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.aspx
XmlSerializer Class
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx

Signature
HTH,
Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com
A pea rants as candy be sieving.
>I am using a method to serialize objects to xml.
> this method is working fine to serialize most of the objects to Xml.
[quoted text clipped - 91 lines]
> </NetPositions>
> </CloseTradeInterface>