Hi Dino,<br><br>If have tweaked your code to reproduce the exception 
that I am facing. Let me know if you need more details.<br><br>thanks,<br>Mustaq<br><br>using
 System;<br>using Microsoft.Scripting;<br>using IronPython.Hosting;<br>
using Microsoft.Scripting.Hosting;<br><br>class Foo<br>{<br>    public 
static void Main(string[] args)<br>    {<br>        AppDomain ad = 
AppDomain.CreateDomain(&quot;foo&quot;);<br>        var engine = 
Python.CreateEngine(ad);<br>
        engine.Runtime.LoadAssembly(<div id=":mz" class="ii gt">typeof(MbrBase).Assembly);<br><br>       
 var code = engine.CreateScriptSourceFromString(@&quot;<br>import 
MbrBase<br>class C(MbrBase):<br>    pass<br><br>a = C()<br>&quot;, 
SourceCodeKind.Statements);<br>
<br>        var scope = engine.CreateScope();<br>        
code.Execute(scope);<br><br>        Console.WriteLine(&quot;Trying to do 
it... {0}&quot;, <a href="http://appdomain.currentdomain.id/" target="_blank">AppDomain.CurrentDomain.Id</a>);<br>
        MbrBase mbr = (MbrBase)scope.GetVariable(&quot;a&quot;);<br><br>//    
 MY CHANGES<br><br>        string isSubClassCode = 
String.Format(&quot;issubclass({0},{1})&quot;, &quot;C&quot;, &quot;MbrBase&quot;);<br>        
ScriptSource script = engine.CreateScriptSourceFromString(isSubClassCode,
 SourceCodeKind.Expression);<br>
        bool result = (bool)script.Execute(scope);<br><br>        if 
(result == true)<br>        {<br>            ObjectOperations ops = 
engine.Operations;<br><br>            object subClass = 
scope.GetVariable(&quot;C&quot;);<br>
            object instance = ops.Call(subClass);<br><br>            mbr
 = instance as MbrBase; <br>        }<br><br>//      END OF MY CHANGE<br>      
 <br>        mbr.DoItVirtually();<br>        mbr.DoIt();<br>        
Console.ReadKey();<br>
    }<br>}<br><br>public class MbrBase : MarshalByRefObject<br>{<br>    
public virtual void DoItVirtually()<br>    {<br>        
Console.WriteLine(&quot;Did it virtually {0}&quot;, <a href="http://appdomain.currentdomain.id/" target="_blank">AppDomain.CurrentDomain.Id</a>);<br>
    }<br>    <br>    public void DoIt()<br>    {<br>        
Console.WriteLine(&quot;Did it {0}&quot;, <a href="http://appdomain.currentdomain.id/" target="_blank">AppDomain.CurrentDomain.Id</a>);<br>   
 }<br>}</div><br><br><div class="gmail_quote">On Tue, Mar 30, 2010 at 10:12 PM, Dino Viehland <span dir="ltr">&lt;<a href="mailto:dinov@microsoft.com">dinov@microsoft.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">









<div link="blue" vlink="purple" lang="EN-US">

<div>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">This works for me w/ 2.6.  I’ve included my simple
repro below which creates a new script engine in a remote app domain, loads my
assembly in, runs some code which subclasses the MBRO base class, instantiates
an instance of this class, and then calls it from a remote app domain. 
The key thing here is that when an MBRO is involved a PythonType should not
need to be serialized – the type should live in the remote app domain and
all execution of that code should also happen in the remote app domain where we
have access to the local PythonType object.  Are you also subclassing
types which don’t derive from MBRO?  It might help to run IronPython
w/ -X:ExceptionDetail if the exception is propagating through IronPython –
that’ll give a better stack trace to understand what’s going on. 
Or if you can tweak the simple repro below to match the behavior you’re
seeing that’d be helpful as well.</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">using System;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">using Microsoft.Scripting;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">using IronPython.Hosting;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">class Foo {</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    public static void Main(string[] args)
{  </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        AppDomain ad =
AppDomain.CreateDomain(&quot;foo&quot;);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        var engine =
Python.CreateEngine(ad);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">       
engine.Runtime.LoadAssembly(typeof(MbrBase).Assembly);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        var code =
engine.CreateScriptSourceFromString(@&quot;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">import MbrBase</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">class C(MbrBase):</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    pass</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">a = C()</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">&quot;, SourceCodeKind.Statements);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        var scope =
engine.CreateScope();</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        code.Execute(scope);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">       
Console.WriteLine(&quot;Trying to do it... {0}&quot;,
<a href="http://AppDomain.CurrentDomain.Id" target="_blank">AppDomain.CurrentDomain.Id</a>);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        MbrBase mbr =
(MbrBase)scope.GetVariable(&quot;a&quot;);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        mbr.DoItVirtually();</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        mbr.DoIt();</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    }</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">}</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">public class MbrBase : MarshalByRefObject {</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    public virtual void DoItVirtually() {</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">       
Console.WriteLine(&quot;Did it virtually {0}&quot;,
<a href="http://AppDomain.CurrentDomain.Id" target="_blank">AppDomain.CurrentDomain.Id</a>);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    }</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    public void DoIt() {</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">       
Console.WriteLine(&quot;Did it {0}&quot;, <a href="http://AppDomain.CurrentDomain.Id" target="_blank">AppDomain.CurrentDomain.Id</a>);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    }</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">}</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<div style="border-width: medium medium medium 1.5pt; border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color blue; padding: 0in 0in 0in 4pt;">

<div>

<div style="border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; padding: 3pt 0in 0in;">

<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;">
<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>] <b>On
Behalf Of </b>mohammad mustaq<br>
<b>Sent:</b> Monday, March 29, 2010 8:13 PM<br>
<b>To:</b> <a href="mailto:users@lists.ironpython.com" target="_blank">users@lists.ironpython.com</a><br>
<b>Subject:</b> [IronPython] IronPython.Runtime.Types.PythonType Is not marked
as Serializable Exception</span></p>

</div>

</div><div><div></div><div class="h5">

<p class="MsoNormal"> </p>

<p class="MsoNormal">Hi,<br>
<br>
I have IronPython embedded in my C# application. I face issues while creating
the python engine in a different appdomain.<br>
<br>
It is imposed that every class in IronPython inherit the .NET base class say
ClassA. ClassA is derived from MarshalByRefObj as I need to pass an instance of
this class to a new appdomain.<br>
I create a new appdomain and pass the instance of ClassA to this Appdomain.
While calling a method in python class through the instance of ClassA I get an
exception mentioning that &quot;Type &#39;IronPython.Runtime.Types.PythonTyp </p>

<div>

<p class="MsoNormal">e&#39; in Assembly &#39;IronPython, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35&#39; is not marked as
serializable&quot;. <br>
<br>
How do I Serialize this PythonType. One way that i know is to modify the
IronPython source and mark the required types as Serializable (but i do not
know where it will lead to and its consequences). Could you please suggest a way
to perform the required operation. Should you need more details let me know.<br>
<br>
thanks,<br>
<span style="color: rgb(136, 136, 136);">Mustaq<br>
</span><br>
P.S. I have used both IronPython 2.0 and 2.6.</p>

</div>

</div></div></div>

</div>

</div>


<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a 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>