.NETGURU
deserialize arraylist
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Greg (VIP)
I'm trying to deserialize an arraylist of string typed items. I have:
[XmlArrayItem ("client",typeof(System.String))]
public ArrayList sClient;

but it's giving me an invalid cast error when I try to deserialize the
class. It serialized from XML fine.
Any idea what's going on?

thanks,
Greg
Reply to this message...
 
    
Jakob Christensen
Hey Greg,

An ArrayList is NOT the same thing as an array which is why you are getting
the invalid cast exception. If you remove the XmlArrayItem attribute it will
work.

HTH,
Jakob.

"Greg" wrote:

[Original message clipped]

Reply to this message...
 
    
Greg (VIP)
Hi Jakob,

I tried using:
[XmlElement("client", typeof(System.String))]
public ArrayList sClient;

and :

[XmlElement("client", typeof(string))]
public ArrayList sClient;

but those did not work either. Same invalid cast error. I double checked
to make sure the values are strings. Any other ideas?

thanks,
Greg

"Jakob Christensen" wrote:

[Original message clipped]

Reply to this message...
 
    
Jakob Christensen
Hey Greg,

Sounds weird. Have you checked the generated XML file to see if any of the
elements are non-strings?

Anyway, if your arraylist only contains strings the serialization works even
without the XmlElementAttribute applied. The XmlSerializer will figure out
that all elements are strings. If this does not work it means that somewhere
you are inserting an element that is not a string. Actually, it seems to me
that the XmlElementAttribute is largely ignored in your case.

I tried this sample and it works fine though:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrollingserializationbyxmlserializerwithattributes.asp

Regards, Jakob.

"Greg" wrote:

[Original message clipped]

Reply to this message...
 
    
Greg (VIP)
I don't know ... can't get it to work. I ended up just changing the
Arraylist to a collection of strings and it works with no other changes. Go
figure.

"Jakob Christensen" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Collections.ArrayList
System.String
System.Xml.Serialization.XmlElementAttribute
System.Xml.Serialization.XmlSerializer
System.Xml.XmlElement




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification