[IronPython] Remoting broken in 2.0?

Dino Viehland dinov at microsoft.com
Thu Jan 22 03:21:02 CET 2009


I believe I have a solution but I don't know if it's ideal, if it'll break other things, or if there are also other spots that need to be updated..  I'll need to talk to the DLR team about it and hopefully they can figure those things out :).  But if you're willing to compile from source you can download the IronPython 2 source code and edit MetaObject.cs.  The changes are easy, just add:

        interface IRemotingMarker {
        }

In the MetaObject class definition.  Then add:

            IRemotingMarker irm = argValue as IRemotingMarker;
            if(irm != null) {
                // remote object, don't check for other interfaces.
                return new ParameterMetaObject(parameterExpression, argValue);
            }

At the beginning of ObjectToMetaObject.

That'll detect remote objects and avoid going down the failing code path.  I'll ping the DLR team now and get the issue on a future DLR design discussion.  If this does turn out to be the right solution (or close to it) we can fix this in 2.0.1.  Thanks for the report!

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Marc Saegesser
> Sent: Wednesday, January 21, 2009 5:21 PM
> To: Discussion of IronPython
> Subject: Re: [IronPython] Remoting broken in 2.0?
> 
> Type 'Microsoft.Linq.Expressions.ParameterExpression' in Assembly
> 'Microsoft.Scripting.Core, Version=0.9.0.0, Culture=neutral,
> PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
> 
> Server stack trace:
>    at
> System.Runtime.Serialization.FormatterServices.InternalGetSerializableM
> embers(RuntimeType
> type)
>    at
> System.Runtime.Serialization.FormatterServices.GetSerializableMembers(T
> ype
> type, StreamingContext context)
>    at
> System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemb
> erInfo()
>    at
> System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSeri
> alize(Object
> obj, ISurrogateSelector surrogateSelector, StreamingContext context,
> SerObjectInfoInit serObjectInfoInit, IFor
> matterConverter converter, ObjectWriter objectWriter)
>    at
> System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serializ
> e(Object
> obj, ISurrogateSelector surrogateSelector, StreamingContext context,
> SerObjectInfoInit serObjectInfoInit, IFormatt
> erConverter converter, ObjectWriter objectWriter)
>    at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(O
> bject
> graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
>    at
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serializ
> e(Stream
> serializationStream, Object graph, Header[] headers, Boolean fCheck)
>    at
> System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SerializeMes
> sage(IMessage
> msg, ITransportHeaders& headers, Stream& stream)
>    at
> System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessM
> essage(IMessage
> msg)
> 
> Exception rethrown at [0]:
>    at
> System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
> reqMsg, IMessage retMsg)
>    at
> System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
> msgData, Int32 type)
>    at
> Microsoft.Scripting.Actions.IDynamicObject.GetMetaObject(Expression
> parameter)
>    at Microsoft.Scripting.Actions.MetaObject.ObjectToMetaObject(Object
> argValue, Expression parameterExpression)
>    at Microsoft.Scripting.Actions.MetaAction.Bind[T](Object[] args)
>    at Microsoft.Scripting.Actions.CallSite`1.CreateNewRule(Rule`1
> originalMonomorphicRule, Object[] args)
>    at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[]
> args)
>    at
> Microsoft.Scripting.Actions.UpdateDelegates.Update4[T,T0,T1,T2,T3,TRet]
> (CallSite
> site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
>    at S$2.Initialize$17()
>    at _stub_$226##76(Closure , CallSite , CodeContext , Object )
>    at Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func`4
> target, CallSite site, Object[] args)
>    at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[]
> args)
>    at
> Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](CallS
> ite
> site, T0 arg0, T1 arg1)
>    at <module>$224##74(Closure , Scope , LanguageContext )
>    at
> Microsoft.Scripting.Runtime.OptimizedScriptCode.InvokeTarget(LambdaExpr
> ession
> code, Scope scope)
>    at Microsoft.Scripting.ScriptCode.Run(Scope scope)
>    at
> IronPython.Hosting.PythonCommandLine.<>c__DisplayClass1.<RunOneInteract
> ion>b__0()
> SystemError: Type 'Microsoft.Linq.Expressions.ParameterExpression' in
> Assembly 'Microsoft.Scripting.Core, Version=0.9.0.0, Culture=neutral,
> PublicKeyToken=31bf3856ad364e35' is not marked as serializab
> le.
> Marc
> 
> 
> 
> On Wed, Jan 21, 2009 at 5:57 PM, Dino Viehland <dinov at microsoft.com>
> wrote:
> > Can you run w/ -X:ExceptionDetail to get the full stack trace?
> >
> > It's presumably trying to serialize it for a call to IDynamicObject
> which has a GetMetaObject(Expression e) method on it.
> >
> > -----Original Message-----
> > From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Marc Saegesser
> > Sent: Wednesday, January 21, 2009 3:46 PM
> > To: Discussion of IronPython
> > Subject: Re: [IronPython] Remoting broken in 2.0?
> >
> > I was already using the typedproxy stuff in my code running under
> > 2.0b3 and my code looks just like the sample code you showed.  It
> > works great in 2.0b3, but throws an exception in 2.0.
> >
> > The class it's complaining about, ParameterExpression, really isn't
> > serializable according to the documentation.  So the question is why
> > is 2.0 trying to serialize a ParameterExpression when 2.0b3 wasn't?
> > My remote object doesn't do anything with Linq or expressions so I'm
> > not sure where it's coming from.
> >
> >
> > Marc
> >
> >
> >
> > On Wed, Jan 21, 2009 at 5:27 PM, Dino Viehland <dinov at microsoft.com>
> wrote:
> >> This is related to 470 but is slightly different.  But in both cases
> the CLR is lying to us and telling us your object does implement the
> interface but it really doesn't (or I'm assuming that's the case, maybe
> whatever you're doing Activator.CreateInstance does implement the
> interface).  But now we're blowing up before the interface cast on the
> remote side because Expression trees aren't serializable (whereas
> before we were blowing up on the other side of the remote call because
> the remote object doesn't actually implement the interface).
> >>
> >> The workaround at the bottom of that bug should work for you.  You
> can create a local "typed proxy" object which goes through the type
> object to get members instead of the instance.  That should avoid the
> interface check and you should be able to talk to the remote object.
> For convenience here's the typed proxy object:
> >>
> >> class typedproxy(object):
> >>    __slots__ = ['obj', 'proxyType']
> >>    def __init__(self, obj, proxyType):
> >>        self.obj = obj
> >>        self.proxyType = proxyType
> >>
> >>    def __getattribute__(self, attr):
> >>        proxyType = object.__getattribute__(self, 'proxyType')
> >>        obj = object.__getattribute__(self, 'obj')
> >>        return getattr(proxyType, attr).__get__(obj, proxyType)
> >>
> >>
> >>
> >> test = typedproxy(System.Activator.GetObject(RemoteTest,
> 'http://localhost:8000/RemoteTest'), RemoteTest)
> >>
> >>
> >> If that doesn't work let us know.
> >>
> >>
> >>
> >> -----Original Message-----
> >> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Marc Saegesser
> >> Sent: Wednesday, January 21, 2009 2:40 PM
> >> To: users
> >> Subject: [IronPython] Remoting broken in 2.0?
> >>
> >> I've been using 2.0b3 for quite some time with good results.  I just
> >> tried to move to the final 2.0 release and ran into a fatal problem.
> >> I use .Net Remoting and when I try to create a proxy to a well known
> >> object using System.Activator.GetObject() I get the following error:
> >>
> >> SystemError: Type 'Microsoft.Linq.Expressions.ParameterExpression'
> in
> >> Assembly 'Microsoft.Scripting.Core, Version=0.9.0.0,
> Culture=neutral,
> >> PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
> >>
> >> The only change was going from 2.0b3 to 2.0.
> >>
> >> I think this is the same problem reported in item 470
> >>
> (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=470)
> >> in June of 2006.
> >>
> >> Any ideas on how to get around the problem?
> >>
> >> Marc
> >> _______________________________________________
> >> Users mailing list
> >> Users at lists.ironpython.com
> >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >> _______________________________________________
> >> Users mailing list
> >> Users at lists.ironpython.com
> >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >>
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list