[Mono-list] XmlIncludeAttribute missing class

Ricardo Gladwell ricardo.gladwell@btinternet.com
Wed, 11 May 2005 15:13:14 +0100


Hi Chris,

Thanks for your response but, if you examine my code example, you will
see that I'm not actually trying to serialize a hashtable so I don't
think this can be the cause of the issue. The private Hashtable I am
using is wrapped by the Folder class which is IEnumerable.

Would this still be causing problems?

Kind regards...

-- Ricardo

Chris Turchin wrote:
> Hi,
> 
> I don't think you can serialize hashtables (easily) to XML:
> 
> http://blogs.msdn.com/psheill/archive/2005/04/09/406823.aspx
> http://codebetter.com/blogs/geoff.appleby/archive/2004/11/13/32005.aspx
> 
> I did something similar a while back in mono with ArrayLists and that worked
> fine:
> 
>         [Serializable]
>         public  class SearchList
>         {
>                 [XmlElement(typeof(SearchType), ElementName = "SearchType")]
>                 public ArrayList Items = new ArrayList();
> etc...
> 
> but I remember reading back then that hastables were a pain...
> 
> Regards,
> 
> --chris
> 
> 
> 
> On Wed, 11 May 2005, Ricardo Gladwell wrote:
> 
> 
>>I'm getting the following exception when I attempt to deserialize some
>>objects in my application using System.Xml.Serialization:
>>
>>System.InvalidOperationException: The type WebPuppy.Model.Site was not
>>expected. Use the XmlInclude or SoapInclude attribute to specify types
>>that are not known statically.
>>
>>I've been careful to include all the relevant objects using the
>>XmlIncludeAttribute so I can't figure out why the XML serializer is not
>>properly finding the Site object. See code fragment below:
>>
>>using System.Collections;
>>using System.IO;
>>using System.Xml.Serialization;
>>
>>public class Test {
>>     public static void Main () {
>>         Configuration configuration = new Configuration();
>>         Site site = new Site();
>>         site.Id = "id";
>>         configuration.Sites.Add( site );
>>         XmlSerializer serializer = new XmlSerializer (typeof
>>(Configuration));
>>         using (FileStream fs = new FileStream ("test.xml",
>>FileMode.Create)) {
>>             serializer.Serialize (fs, configuration);
>>         }
>>     }
>>}
>>
>>public class Configuration {
>>
>>	Folder sites = new Folder();
>>
>>	public Folder Sites
>>	{
>>		get {
>>			return sites;
>>		}
>>		set {
>>			this.sites = value;
>>		}
>>	}
>>
>>}
>>
>>[XmlInclude (typeof (Folder))]
>>[XmlInclude (typeof (Site))]
>>public abstract class Artifact {
>>	public string Id;
>>}
>>
>>public class Folder : Artifact, IEnumerable
>>{
>>	private Hashtable artifacts = new Hashtable ();
>>
>>	public IEnumerator GetEnumerator ()
>>	{
>>		return artifacts.Values.GetEnumerator ();
>>	}
>>
>>	public void Add(object o) {
>>         Artifact artifact = (Artifact) o;
>>		artifacts[artifact.Id] = (Artifact) artifact;
>>	}
>>}
>>
>>public class Site : Folder
>>{
>>}
>>_______________________________________________
>>Mono-list maillist  -  Mono-list@lists.ximian.com
>>http://lists.ximian.com/mailman/listinfo/mono-list