<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thanks Michael for the advice. Must appreciated. Unfortunately I hasn't
worked out yet tho :(<br>
<br>
I can use pickle from C# using Evaluate, or from within a Python class,
on a "pure" Python object. However any attempt at pickling a python
object that derives from a C# base result in an exception like this:<br>
Cannot convert MyObject(&lt;MyObject object at 0x000000000000002B&gt;)
to Int32<br>
<br>
Exploring further, I came across Ops.GetDynamicType() and
Ops.GetAttrsNames() which I thought might be helpful to get the
attributes of an object and serialize it somehow (manually), but
GetAttrNames requires an ICallerContext, and I can't see how to get one
of those.<br>
<br>
It seems that whilst serializing .NET classes is trivial, and
serializing python classes is trivial, serializing something that
touches both is proving quite difficult.<br>
<br>
Any further suggestions gratefully received!<br>
<br>
Thanks, Paul<br>
<br>
Michael Foord wrote:
<blockquote cite="mid:47E8FA22.2030407@voidspace.org.uk" type="cite">
  <pre wrap="">Paul Turbett wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hi,

I'm using IP as a scripting engine in a C# app. I have various Python 
classes that derive from a C# base class, and have there own additional 
data &amp; functionality.

I would like to be able to serialize instances of the Python classes 
from the C# host for persistence across sessions. Using the standard 
BinaryFormatter with the Serializable attribute is not working - I get 
an error about the python class not being marked as serializable (the C# 
base class is marked as serializable though).

How can I serialize python objects from C#? Should I use reflection to 
roll my own serializer, or is there something in one of the lesser 
documented assemblies like Ops I should use?
  
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Typically for serializing Python objects you would use pickle [1]. The 
'dumps' function returns a string (make sure you use the text protocol 
for IronPython).

You could then execute code inside the Python engine to serialize / 
deserialize objects. I've not tried this for instances that inherit from 
C# base classes - but it should work fine. :-)

Michael Foord
<a class="moz-txt-link-freetext" href="http://www.ironpythoninaction.com">http://www.ironpythoninaction.com</a>

.. [1] <a class="moz-txt-link-freetext" href="http://docs.python.org/lib/module-pickle.html">http://docs.python.org/lib/module-pickle.html</a>

  </pre>
  <blockquote type="cite">
    <pre wrap="">I'm using IP 1.1.1 (but will move to 2.0 if that will help). Any 
pointers &amp; advice greatly appreciated!

Thanks, Paul
_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>
<a class="moz-txt-link-freetext" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a>
  
    </pre>
  </blockquote>
  <pre wrap=""><!---->
_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>
<a class="moz-txt-link-freetext" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a>

  </pre>
</blockquote>
<br>
</body>
</html>