Hi, back again... I've installed IronPython 2.0A1 which I believe is based on the Silverlight DLR stuff and done some more testing. Here's the code I'm runnig from the ipy.exe console:
import
clrimport System
clr.AddReference(
"System.Xml")
from
System import *
from
System.IO import *
from
System.Xml.Serialization import *class Myclass(System.Object):
name = None
age = 0
def __init__(self):
self.name =
""
self.age = 0
def __init__(self, n, a):
self.name = n
self.age = a
def __str__(self):
return "%s, %s years old"%(self.name,self.age)
a = Myclass(
"Angie",66)print(a)
ser = XmlSerializer(a.GetType())
writer = StreamWriter("C:/dump.xml")
ser.Serialize(writer, a)
writer.Close()
And here's the output from running that piece:
C:\IronPython-2.0A1\IronPython-2.0A1>ipy Program.py
Angie, 66 years old
Traceback (most recent call last):
File Program.py, line 26, in Initialize
File , line 0, in _stub_##31
File , line 0, in NonDefaultNew##36
File , line 0, in .ctor##38
File System.Xml, line unknown, in .ctor
File System.Xml, line unknown, in .ctor
File System.Xml, line unknown, in ImportTypeMapping
File System.Xml, line unknown, in GetTypeModel
File System.Xml, line unknown, in GetTypeDesc
File System.Xml, line unknown, in CheckSupported
SystemError: IronPython.NewTypes.System.Object_1 cannot be serialized because it does not have a parameterless constructor.
Hope this helps. Again, I'm new dynamic languages and not sure how well serialization is supposed to work here. I'm also unfamilar to how constructor overloading works in python I'm afraid, as it might have something to do with the error in this case.
Thanks,
Johan