[IronPython] Serializing IronPython classes

Dino Viehland dinov at microsoft.com
Mon Oct 6 18:08:11 CEST 2008


I would strongly encourage you to use cPickle or pickle instead of .NET serialization.  In 2.0 all .NET serializable types can also be pickled - they define __reduce_ex__ which handles this.

First off we should be setting the serializable bit on subclasses that are serializable - that's just a bug that we're not doing that.  But once we've done that the problem w/ .NET serialization is that ultimately we need a static method or type that we can point at that does the deserialization.  For a user defined type in Python we will need to be able to deserialize the type, the module the type lives in, and presumably even the ScriptRuntime which holds the module.  Pickle handles this by serializing the module & type name but w/o a ScriptRuntime we couldn't even get at that.  We might have been able to require a ScriptRuntime to be smuggled in the StreamingContext but it's not clear that it would work well.

So if you really want .NET serialization we can fix the bug - but you'll need to implement ISerializable and figure out some way to deal getting the class, module, and runtime information saved/restored yourself.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Serge
Sent: Sunday, October 05, 2008 9:24 PM
To: users at lists.ironpython.com
Subject: [IronPython] Serializing IronPython classes

I've run into problems with serialization. I have a serializable class defined in C# which gets extended from IP, however when I try to serialize a collection of both parent and child instances, I get an exception saying that the IP generated class is not marked as serializable.

With the lack of attributes, I am guessing I must do something else to enable serialization?

Regards, Serge.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081006/08a8abc7/attachment.html>


More information about the Ironpython-users mailing list