Hi Dino,
If have tweaked your code to reproduce the exception that I am facing. Let
me know if you need more details.
thanks,
Mustaq
using System;
using Microsoft.Scripting;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
class Foo
{
public static void Main(string[] args)
{
AppDomain ad = AppDomain.CreateDomain("foo");
var engine = Python.CreateEngine(ad);
engine.Runtime.LoadAssembly(
typeof(MbrBase).Assembly);
var code = engine.CreateScriptSourceFromString(@"
import MbrBase
class C(MbrBase):
pass
a = C()
", SourceCodeKind.Statements);
var scope = engine.CreateScope();
code.Execute(scope);
Console.WriteLine("Trying to do it... {0}",
AppDomain.CurrentDomain.Id <http://appdomain.currentdomain.id/>);
MbrBase mbr = (MbrBase)scope.GetVariable("a");
// MY CHANGES
string isSubClassCode = String.Format("issubclass({0},{1})", "C",
"MbrBase");
ScriptSource script =
engine.CreateScriptSourceFromString(isSubClassCode,
SourceCodeKind.Expression);
bool result = (bool)script.Execute(scope);
if (result == true)
{
ObjectOperations ops = engine.Operations;
object subClass = scope.GetVariable("C");
object instance = ops.Call(subClass);
mbr = instance as MbrBase;
}
// END OF MY CHANGE
mbr.DoItVirtually();
mbr.DoIt();
Console.ReadKey();
}
}
public class MbrBase : MarshalByRefObject
{
public virtual void DoItVirtually()
{
Console.WriteLine("Did it virtually {0}",
AppDomain.CurrentDomain.Id<http://appdomain.currentdomain.id/>
);
}
public void DoIt()
{
Console.WriteLine("Did it {0}",
AppDomain.CurrentDomain.Id<http://appdomain.currentdomain.id/>
);
}
}
On Tue, Mar 30, 2010 at 10:12 PM, Dino Viehland <[email protected]> wrote:
> 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.
>
>
>
> using System;
>
> using Microsoft.Scripting;
>
> using IronPython.Hosting;
>
>
>
> class Foo {
>
> public static void Main(string[] args) {
>
> AppDomain ad = AppDomain.CreateDomain("foo");
>
> var engine = Python.CreateEngine(ad);
>
> engine.Runtime.LoadAssembly(typeof(MbrBase).Assembly);
>
>
>
> var code = engine.CreateScriptSourceFromString(@"
>
> import MbrBase
>
> class C(MbrBase):
>
> pass
>
>
>
> a = C()
>
> ", SourceCodeKind.Statements);
>
>
>
> var scope = engine.CreateScope();
>
> code.Execute(scope);
>
>
>
> Console.WriteLine("Trying to do it... {0}",
> AppDomain.CurrentDomain.Id);
>
> MbrBase mbr = (MbrBase)scope.GetVariable("a");
>
> mbr.DoItVirtually();
>
> mbr.DoIt();
>
> }
>
> }
>
>
>
> public class MbrBase : MarshalByRefObject {
>
> public virtual void DoItVirtually() {
>
> Console.WriteLine("Did it virtually {0}",
> AppDomain.CurrentDomain.Id);
>
> }
>
>
>
> public void DoIt() {
>
> Console.WriteLine("Did it {0}", AppDomain.CurrentDomain.Id);
>
> }
>
> }
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *mohammad mustaq
> *Sent:* Monday, March 29, 2010 8:13 PM
> *To:* [email protected]
> *Subject:* [IronPython] IronPython.Runtime.Types.PythonType Is not marked
> as Serializable Exception
>
>
>
> Hi,
>
> I have IronPython embedded in my C# application. I face issues while
> creating the python engine in a different appdomain.
>
> 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.
> 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 "Type 'IronPython.Runtime.Types.PythonTyp
>
> e' in Assembly 'IronPython, Version=2.0.0.0, Culture=neutral,
> PublicKeyToken=31bf3856ad364e35' is not marked as serializable".
>
> 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.
>
> thanks,
> Mustaq
>
> P.S. I have used both IronPython 2.0 and 2.6.
>
> _______________________________________________
> Users mailing list
> [email protected]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com