Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com