ethershadow
New Member
I'm using an API to search for hotels, we will call this type 1. It gets deserialized by \[code\]XmlSerializer\[/code\] into my \[code\]Hotel\[/code\] class and this all works fine as expected. My issue is when I'm making another API call, which we will call type 2, and want to re-use my \[code\]Hotel\[/code\] class.The API calls are pretty similar, type 1 returns a list of hotels nearby and type 2 returns further details for a particular hotel. One of the extra pieces of information I'm trying to parse is images. In type 1 and in my \[code\]Hotel\[/code\] class I have:\[code\][XmlElement("images")]public virtual string ImageURL { get; set; }\[/code\]which works fine for the type 1 call. Now for the type 2 call it is an array of images rather than just the one string. I've created a new class called \[code\]Hotel2\[/code\] which derives from \[code\]Hotel\[/code\] and looks like this:\[code\]public class Hotel2 : Hotel{ [XmlArray("images")] [XmlArrayItem("url")] public List<string> ImageURLs { get; set; } [XmlIgnore] public override string ImageURL { get { return (this.ImageURLs != null && this.ImageURLs.Count > 0 ? this.ImageURLs[0] : String.Empty); } }\[/code\]}and you can see I have a new property \[code\]ImageURLs\[/code\] (note the 's') which handles the array. I'm also overriding the \[code\]ImageURL\[/code\] property which returns the first Image in the \[code\]ImageURLs\[/code\] collection and marking it as \[code\]XmlIgnore\[/code\] so it doesn't get deserialized.The issue is that it seems \[code\]XmlSerializer\[/code\] ignores my \[code\]XmlIgnore\[/code\] property and attempts to deserialize the base property thus resulting in this exception: \[code\]The XML element 'images' from namespace '' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.\[/code\]Any idea what I can do here? I've also tried to hide the property with \[code\]new\[/code\] to no success.