[Mono-dev] XmlSerialize: different behavior Windows and Linux/mono

Mario1 marioecht at gmx.de
Fri Apr 17 06:45:32 EDT 2009


Hello!

The following simple example does not run on a Suse 10.3 Linux computer with
mono 2.4. 

using System.Xml.Serialization;
using System.Collections.Generic;

namespace Example.XmlSerialize {

  public class XmlSerializeTestClass {
    public List<string> val;

//    [XmlIgnore]
    public IEnumerable<string> VAL {
      get { return val; }
    }
  }

  class XmlSerializeTest {

    static public int Main() {

      XmlSerializer xmlSerializer = new
XmlSerializer(typeof(XmlSerializeTestClass));

      System.Console.WriteLine("XmlSerializer constructor OK.");
      return 0;
    }
  }
}

The result is:

Unhandled Exception: System.InvalidOperationException: There was an error
reflecting type 'Example.XmlSerialize.XmlSerializeTestClass'. --->
System.InvalidOperationException: To be XML serializable, types which
inherit from IEnumerable must have an implementation of Add(System.String)
at all levels of their inheritance hierarchy.
System.Collections.Generic.IEnumerable`1[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] does not
implement Add(System.String).
  at System.Xml.Serialization.TypeData.get_ListItemType () [0x00000] 
  at System.Xml.Serialization.TypeData.get_ListItemTypeData () [0x00000] 
  at System.Xml.Serialization.TypeData..ctor (System.Type type,
System.String elementName, Boolean isPrimitive,
System.Xml.Serialization.TypeData mappedType,
System.Xml.Schema.XmlSchemaPatternFacet facet) [0x00000] 
  at System.Xml.Serialization.TypeData..ctor (System.Type type,
System.String elementName, Boolean isPrimitive) [0x00000] 
  at System.Xml.Serialization.TypeTranslator.GetTypeData (System.Type
runtimeType, System.String xmlDataType) [0x00000] 
  at System.Xml.Serialization.TypeTranslator.GetTypeData (System.Type type)
[0x00000] 
  at System.Xml.Serialization.XmlReflectionImporter.GetReflectionMembers
(System.Type type) [0x00000] 
  at System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping
(System.Xml.Serialization.TypeData typeData,
System.Xml.Serialization.XmlRootAttribute root, System.String
defaultNamespace) [0x00000] 
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping
(System.Xml.Serialization.TypeData typeData,
System.Xml.Serialization.XmlRootAttribute root, System.String
defaultNamespace) [0x00000] 
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping
(System.Xml.Serialization.TypeData typeData,
System.Xml.Serialization.XmlRootAttribute root, System.String
defaultNamespace) [0x00000] 
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping
(System.Type type, System.Xml.Serialization.XmlRootAttribute root,
System.String defaultNamespace) [0x00000] 
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type,
System.Xml.Serialization.XmlAttributeOverrides overrides, System.Type[]
extraTypes, System.Xml.Serialization.XmlRootAttribute root, System.String
defaultNamespace) [0x00000] 
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type)
[0x00000] 
  at Example.XmlSerialize.XmlSerializeTest.Main () [0x00000] 

But it run on a Windows XP computer.
The example demonstrated only the behavior and does not result in a sense.

And yes, if I uncomment [XmlIgnore] then it run on both systems.

My question is whether that is a mono error? Then the error could be
repaired.
Or is it a Windows error? Then that is problematic. Because my existing
program code cannot be simply excecuted on Linux with mono. Due to this
behavior.

Perhaps someone has information to the different behavior with Windows and
Linux/mono.

Mario

-- 
View this message in context: http://www.nabble.com/XmlSerialize%3A-different-behavior-Windows-and-Linux-mono-tp23095271p23095271.html
Sent from the Mono - Dev mailing list archive at Nabble.com.



More information about the Mono-devel-list mailing list