Xml Serialization of Custom Collections deriving from CollectionBase.

Hi,

I have seen several posts on the net on the following issue of xml serialization of custom collection classes deriving from CollectionBase.

"you must implement a default accessor on AccountCollection because it inherits from ICollection”.

System.InvalidOperationException: You must implement adefaultaccessor on
MyNamespace.MyClassList because it inherits fromICollection

http://www.dotnet247.com/247reference/msgs/5/27024.aspx

http://www.topxml.com/ASPNET-Webservices/rn-245057_ICollection-default-accessor.aspx

And the obivous answer for all these problems is implementing the "default accessor" for your custom class. But no where I could find details on, why does the xmlserializer need a default acceessor implementation.

I would like to know the working of xmlserailizer when serailizing the custom collection, and why and how it uses the deault accessor for serailization.

Thanks in advance,

Laxmi.



[1979 byte] By [Laxmi.] at [2007-12-28]
# 1
The solution has been given in the first url which you have mentioned (by Steven Cheng). Have you tried that solution?
SaravanaKumar_1977 at 2007-9-4 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 2

Thanks Saravan,

Between, I know the sloution to this exception. I am concerened from understanding perspective of need for the implementation of default accessor for Custom collection class.

Thanks,

Laxmi.

Laxmi. at 2007-9-4 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 3

You know any collection can be accessed via index. If you have a collection the first element can be accessed by the "0" index, the second element via "1", etc... Thats why the default accessor implementation comes. Whenever you are creating custom collection class, you should implement the default accessor. Thats why this exception comes.

Saravana Kumar

SaravanaKumar_1977 at 2007-9-4 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...

.NET Development

Site Classified