Best effort serialization by BadSingleton · Pull Request #1892 · pythonnet/pythonnet

I am also experiencing this issue when trying to use this library with Unity3D. Here is the specific serialization error I get on shutdown. @BadSingleton, does your fix prevent this and allow you to initialize and shutdown the python engine multiple times without error?

Got exception during shutdown: 
Message:Type '__System_Action`1\[\[System_String\, mscorlib\, Version=4_0_0_0\, Culture=neutral\, PublicKeyToken=b77a5c561934e089\]\]Dispatcher' in Assembly '__Python_Runtime_Generated_Assembly0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
  at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers (System.RuntimeType type) [0x00045] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.FormatterServices+<>c__DisplayClass9_0.<GetSerializableMembers>b__0 (System.Runtime.Serialization.MemberHolder _) [0x00000] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) [0x00034] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.FormatterServices.GetSerializableMembers (System.Type type, System.Runtime.Serialization.StreamingContext context) [0x0005e] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo () [0x0003d] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize (System.Object obj, System.Runtime.Serialization.ISurrogateSelector surrogateSelector, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.Formatters.Binary.SerObjectInfoInit serObjectInfoInit, System.Runtime.Serialization.IFormatterConverter converter, System.Runtime.Serialization.Formatters.Binary.ObjectWriter objectWriter, System.Runtime.Serialization.SerializationBinder binder) [0x00158] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize (System.Object obj, System.Runtime.Serialization.ISurrogateSelector surrogateSelector, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.Formatters.Binary.SerObjectInfoInit serObjectInfoInit, System.Runtime.Serialization.IFormatterConverter converter, System.Runtime.Serialization.Formatters.Binary.ObjectWriter objectWriter, System.Runtime.Serialization.SerializationBinder binder) [0x00006] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo typeNameInfo) [0x00101] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize (System.Object graph, System.Runtime.Remoting.Messaging.Header[] inHeaders, System.Runtime.Serialization.Formatters.Binary.__BinaryWriter serWriter, System.Boolean fCheck) [0x001d3] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header[] headers, System.Boolean fCheck) [0x0006e] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph) [0x00000] in <4c36328e5e3c40ecaf35733ee9461b26>:0 
  at Python.Runtime.RuntimeData.Stash () [0x00049] in <17d3e183cc45426f82a1a9207d7443a1>:0 
  at Python.Runtime.Runtime.Shutdown () [0x00030] in <17d3e183cc45426f82a1a9207d7443a1>:0 
  at Python.Runtime.PythonEngine.Shutdown () [0x00064] in <17d3e183cc45426f82a1a9207d7443a1>:0