[IronPython] Serializing IronPython classes

Dino Viehland dinov at microsoft.com
Tue Oct 7 04:49:33 CEST 2008

Ahh, that sounds like a bad bug, but I think I know what's causing it - we're hitting the new.NET serialization support because __reduce_ex__ is now defined for you :)  Can you add an override that dispatches __reduce_ex__ to the object version, eg:

def __reduce_ex__(self, *args):
    return object.__reduce_ex__(self, *args)

We should probably do that automatically for user-defined instances which should be easy to do if this works for you.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Serge
Sent: Monday, October 06, 2008 7:36 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Serializing IronPython classes

Thanks for the heads up, however trying to use cPickle, I still get the error saying that the child class is not marked as serializable..?
On 10/7/08, Dino Viehland <dinov at microsoft.com<mailto:dinov at microsoft.com>> wrote:

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> [mailto: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<mailto: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.

Users mailing list
Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081006/2ec8555f/attachment.html>

More information about the Ironpython-users mailing list