[Ironpython-users] SerializationException from IronPython.Runtime.Types.PythonType
alanscottmacdonald at gmail.com
Fri Jan 13 09:37:45 CET 2012
Thanks for the response. I understand what you are saying.
I have also realised that at the moment because I catch the exception and
instantiate a new Exception using the formatted information string (so that
calling code need know nothing about ScriptEngine formatting services). I
can move that try catch into the actual execution method in the remote
domain and then rethrow the formatted exception which is essentially string
based. That works for now, but I'm not sure it's a very good approach.
Changing unmarshallable objects into strings would essentially be I guess,
a similar compromise.
Thanks for your time and input.
On 12 January 2012 18:35, Dino Viehland <dinov at microsoft.com> wrote:
> Are you creating the tracing delegate in the remote app domain? You
> should be able to create a class which derives from MarshalByRefObject and
> then create an instance of that object in the remote domain. You can then
> call a method on that MBRO which does the ScriptEngine.SetTrace() call (you
> can safely pass the script engine instance across when you create the
> MBRO). If you want to marshal the results back to your main app domain you
> can also create an MBRO in your local domain that you pass through when you
> construct the remote MBRO and then you can call some method which passes
> strings instead of unmarshallable objects.****
> ** **
> *From:* ironpython-users-bounces+dinov=microsoft.com at python.org [mailto:
> ironpython-users-bounces+dinov=microsoft.com at python.org] *On Behalf Of *Alan
> *Sent:* Thursday, January 12, 2012 1:34 AM
> *To:* ironpython-users at python.org
> *Subject:* [Ironpython-users] SerializationException from
> ** **
> I am experiencing an exception when tracing and would appreciate some
> I am hosting IronPython 2.7.1 in a .Net 4 C# host. The host creates a new
> app domain to run IronPython scripts in. At the moment due to some
> security exceptions I've given the new app domain unrestricted permissions
> (I will try and reduce this later). When the python script is executed it
> runs via an asynchronous delegate and when complete catches any exceptions
> during the running of the script. This was all working fine and if the
> python script has an error in it then the exception is caught in the async
> callback method.
> However I have since added tracing via a call to
> ScriptEngine.SetTrace(myDelegate) so I can allow stepping through the
> script one line at a time (based on http://devhawk.net/tag/debugger/).
> When the script has no errors it executes fine with tracing enabled or
> disabled. However if the script has an error in it and tracing is enabled
> then trying to catch and format the exception in the async delegate
> callback causes a SerializationException on
> IronPython.Runtime.Types.PythonType. When tracing is not enabled the
> exception is caught and formatted successfully.
> I tried to disable tracing in the catch block before formatting the
> exception but this makes no difference. I understand that this is related
> to sending the exception information from one app domain to another but I'm
> not sure what I can do to get round it and what extra information it is
> trying to send when tracing is enabled. My tracing delegate does nothing
> with exceptions.
> Code that creates the new app domain and starts the async call to execute
> the method for the object in the new app domain:
> public void Run()
> if (newDomainInstance == null)
> Execute method = newDomainInstance.ExecuteCode;
> method.BeginInvoke(RunComplete, method);
> The async callback is the following code:
> private void RunComplete(IAsyncResult cookie)
> Complete = true;
> Execute method = (Execute)cookie.AsyncState;
> catch (AppDomainUnloadedException adue)
> //Do nothing because we've deliberately pulled the app
> domain out from under it.
> catch (Exception ex)
> String extractedMessage =
> OnExecutionError(new Exception(extractedMessage));
> The exception occurs on String extractedMessage =
> Exception stacktrace:
> System.Runtime.Serialization.SerializationException was unhandled
> Message=Type 'IronPython.Runtime.Types.PythonType' in Assembly
> 'IronPython, Version=18.104.22.168, Culture=neutral,
> PublicKeyToken=7f709c5b713576e1' is not marked as serializable.
> Server stack trace:
> type, StreamingContext context)
> obj, ISurrogateSelector surrogateSelector, StreamingContext context,
> SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter,
> ObjectWriter objectWriter, SerializationBinder binder)
> objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
> graph, Header inHeaders, __BinaryWriter serWriter, Boolean fCheck)
> serializationStream, Object graph, Header headers, Boolean fCheck)
> reqStmBuff, SmuggledMethodCallMessage smuggledMcm,
> SmuggledMethodReturnMessage& smuggledMrm)
> Exception rethrown at :
> at System.Threading.Thread.InternalCrossContextCallback(Context
> ctx, IntPtr ctxID, Int32 appDomainID, InternalCrossContextDelegate
> ftnToCall, Object args)
> at System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state, Boolean
> at System.Threading.ThreadPoolWorkQueue.Dispatch()
> at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
> Any help would be appreciated. If it helps I can show more code or if
> anything is unclear please let me know. I didn't want to make it too long
> and include unneccessary details.
> Thanks for your time.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironpython-users