Okay now this is getting interesting. I assumed that the warning was about the child class, but I'm not sure. A bit of info: The parent C# class is called Object. I did the override on on __reduce_ex__ as you suggested but trying to pickle still produced the same error: <br>
<br>Type 'IronPython.NewTypes.Engine.Object_1$2' in Assembly 'Snippets.scripting, Version=<a href="http://0.0.0.0">0.0.0.0</a>, Culture=neutral, PublicKeyToken=null' is not marked as serializable.<br><br>For curiosity, I called __reduce_ex__ on a child instance and got the following error: expected Vector2, got Object_1$2<br>
<br>There are several Microsoft.Xna.Framework.Vector2 members and it looks like they're being replaced by this Object_1$2 which I assumed at first to be the child class because of its name. <br>__reduce_ex__ on the parent instances works fine. I'm out of my depth here so I can't give more meaningful information.<br>
<br><div><span class="gmail_quote">On 10/7/08, <b class="gmail_sendername">Dino Viehland</b> <<a href="mailto:dinov@microsoft.com">dinov@microsoft.com</a>> wrote:</span><blockquote class="gmail_quote" style="margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; margin-left: 0.80ex; border-left-color: #cccccc; border-left-width: 1px; border-left-style: solid; padding-left: 1ex">
<div lang="EN-US" link="#0000ff" vlink="#800080"><div><p><span style="font-size: 11pt; color: #1f497d">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 </span><span style="font-size: 11pt; font-family: Wingdings; color: #1f497d">J</span><span style="font-size: 11pt; color: #1f497d"> Can you add an override that dispatches __reduce_ex__ to the object version, eg:</span></p>
<p><span style="font-size: 11pt; color: #1f497d"> </span></p><p><span style="font-size: 11pt; color: #1f497d">def __reduce_ex__(self, *args): </span></p><p><span style="font-size: 11pt; color: #1f497d"> return object.__reduce_ex__(self, *args)</span></p>
<p><span style="font-size: 11pt; color: #1f497d"> </span></p><p><span style="font-size: 11pt; color: #1f497d">We should probably do that automatically for user-defined instances which should be easy to do if this works for you.</span></p>
<p><span style="font-size: 11pt; color: #1f497d"> </span></p><div style="border-top-color: #000000; border-left-color: #000000; border-right-color: #000000; border-bottom-color: #000000; border-top-width: medium; border-left-width: medium; border-right-width: medium; border-bottom-width: medium; border-top-style: none; border-left-style: none; border-right-style: none; border-bottom-style: none; border-top-color: #b5c4df; border-top-width: 1pt; border-top-style: solid; padding-top: 3pt; padding-right: 0in; padding-bottom: 0in; padding-left: 0in">
<p><b><span style="font-size: 10pt">From:</span></b><span style="font-size: 10pt"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Serge<br>
<b>Sent:</b> Monday, October 06, 2008 7:36 PM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] Serializing IronPython classes</span></p></div><div><span class="e" id="q_11cd53690e8f6994_1"><p> </p>
<p style="margin-bottom: 12pt">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..? </p><div><p><span>On 10/7/08, <b>Dino Viehland</b> <<a href="mailto:dinov@microsoft.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">dinov@microsoft.com</a>> wrote:</span></p>
<div><div><p><span style="font-size: 11pt; color: #1f497d">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. </span></p>
<p><span style="font-size: 11pt; color: #1f497d"> </span></p><p><span style="font-size: 11pt; color: #1f497d">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.</span></p>
<p><span style="font-size: 11pt; color: #1f497d"> </span></p><p><span style="font-size: 11pt; color: #1f497d">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.</span></p>
<p><span style="font-size: 11pt; color: #1f497d"> </span></p><div style="border-top-color: #000000; border-left-color: #000000; border-right-color: #000000; border-bottom-color: #000000; border-top-width: medium; border-left-width: medium; border-right-width: medium; border-bottom-width: medium; border-top-style: none; border-left-style: none; border-right-style: none; border-bottom-style: none; border-top-color: #b5c4df; border-top-width: 1pt; border-top-style: solid; padding-top: 3pt; padding-right: 0in; padding-bottom: 0in; padding-left: 0in">
<p><b><span style="font-size: 10pt">From:</span></b><span style="font-size: 10pt"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Serge<br>
<b>Sent:</b> Sunday, October 05, 2008 9:24 PM<br><b>To:</b> <a href="mailto:users@lists.ironpython.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">users@lists.ironpython.com</a><br><b>Subject:</b> [IronPython] Serializing IronPython classes</span></p>
</div><p> </p><p>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.<br>
<br> With the lack of attributes, I am guessing I must do something else to enable serialization?<br><br> Regards, Serge.</p></div></div><p style="margin-bottom: 12pt"><br> _______________________________________________<br>
Users mailing list<br><a href="mailto:Users@lists.ironpython.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a></p>
</div><p> </p></span></div></div></div><br>_______________________________________________<br> Users mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br><br></blockquote>
</div><br>