title: System.Threading.ExecutionContext doesn't implement interface System.IDisposable
body: <p>In our application we are currently moving to <code>System.Threading.Tasks.Dataflow</code> to manage all communications. But now each time we use our Network Client/Server classes in any custom <code>SynchronizationContext</code> we get an exception. </p>
  
  <blockquote>
    <p><em>"System.Threading.ExecutionContext doesn't implement interface
    System.IDisposable".</em></p>
  </blockquote>
  
  <p>I don't see how this is even possible. We never change or play with any threads execution contexts. The closest to it that we do is</p>
  
  <pre><code>    SynchronizationContext.SetSynchronizationContext (new GtkSynchronizationContext ());
      Scheduler = TaskScheduler.FromCurrentSynchronizationContext ();
      Factory = new TaskFactory (Scheduler);
  </code></pre>
  
  <p>I don't see why a custom <code>SynchronizationContext</code> would make DataFlow crash like this.
  What follows is the output of the application leading to the DataFlow exception.</p>
  
  <pre><code>madrang@Qosmio-X770:~$ '/home/madrang/WorkSpace/linsft/Source/Invensys/Build/runbuild' 
  Engine Initialize started
  ==============================================================================
  Application Information
  ------------------------------------------------------------------------------
  Program      : /home/madrang/WorkSpace/linsft/Source/Invensys/Build/Bin/Linsft.Engine.dll
  Time         : 14/04/2013 04:46:02
  User         : madrang
  Computer     : Qosmio-X770
  OS           : Linux64
  Processors   : 8
  Working Set  : 0
  Framework    : 4.0.30319.1
  Run Time     : 00:00:01.6015700
  ------------------------------------------------------------------------------
  Loaded Modules
  ------------------------------------------------------------------------------
  /usr/bin/mono||0
  /usr/bin/mono||3031040
  /usr/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll|4.0.0.0|188416
  /usr/lib/mono/gac/System.Runtime.Serialization/3.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll|3.0.0.0|196608
  /usr/lib/mono/gac/System.ServiceModel/3.0.0.0__b77a5c561934e089/System.ServiceModel.dll|3.0.0.0|1396736
  /usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll|4.0.0.0|1748992
  /usr/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll|4.0.0.0|1273856
  /usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll|4.0.0.0|798720
  /home/madrang/WorkSpace/linsft/Source/Invensys/Build/Bin/NLog.dll|2.0.0.0|319488
  /home/madrang/WorkSpace/linsft/Source/Invensys/Build/Bin/Mono.Addins.dll|1.0.0.0|237568
  /home/madrang/WorkSpace/linsft/Source/Invensys/Build/Bin/Mono.Addins.Setup.dll|1.0.0.0|131072
  /lib/x86_64-linux-gnu/libnss_files-2.17.so||49152
  /lib/x86_64-linux-gnu/libnss_nis-2.17.so||45056
  /lib/x86_64-linux-gnu/libnsl-2.17.so||94208
  /lib/x86_64-linux-gnu/libnss_compat-2.17.so||32768
  /usr/lib/mono/4.0/mscorlib.dll|4.0.0.0|2867200
  /usr/lib/locale/locale-archive||2920448
  /lib/x86_64-linux-gnu/libc-2.17.so||1826816
  /lib/x86_64-linux-gnu/libpthread-2.17.so||98304
  /lib/x86_64-linux-gnu/libdl-2.17.so||12288
  /lib/x86_64-linux-gnu/librt-2.17.so||28672
  /lib/x86_64-linux-gnu/libm-2.17.so||1060864
  /lib/x86_64-linux-gnu/ld-2.17.so||143360
  /usr/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll|4.0.0.0|126976
  /home/madrang/WorkSpace/linsft/Source/Invensys/Build/Bin/Linsft.Engine.dll|0.5.4849.6350|36864
  /home/madrang/WorkSpace/linsft/Source/Invensys/Build/Invensys.exe|1.0.4845.22748|8192
  /run/shm/mono.8910||4096
  ------------------------------------------------------------------------------
  Loaded Assembly
  ------------------------------------------------------------------------------
  Mono.Posix, 4.0.0.0
  System.Runtime.Serialization, 3.0.0.0
  System.ServiceModel, 3.0.0.0
  System, 4.0.0.0
  System.Configuration, 4.0.0.0
  System.Xml, 4.0.0.0
  System.Core, 4.0.0.0
  NLog, 2.0.0.0
  Mono.Addins, 1.0.0.0
  Mono.Addins.Setup, 1.0.0.0
  Linsft.Engine, 0.5.4849.6350
  Invensys, 1.0.4845.22748
  mscorlib, 4.0.0.0
  ==============================================================================
  Registed new scheduler: ThreadPool
  Addin Loaded: Linsft.Engine
  Assembly Loaded ICSharpCode.SharpZipLib, 2.84.0.0
  Assembly Loaded Mono.Addins.CecilReflector, 1.0.0.0
  Assembly Loaded Mono.CSharp, 4.0.0.0
  Assembly Loaded NLog.Extended, 2.0.0.0
  Assembly Loaded xunit, 1.9.1.1600
  Assembly Loaded xunit.extensions, 1.9.1.1600
  Assembly Loaded xunit.runner.utility, 1.9.1.1600
  Addin Loaded: Linsft.Invensys
  Starting new task in default scheduler: Linsft.CommandExtensionNode: Id=Linsft.Core.IdleScheduler.Initialize, Linsft.Core.IdleScheduler.Initialize()
  Assembly Loaded Linsft.Core, 1.0.4850.6090
  Assembly Loaded Linsft.Configuration, 0.0.0.1
  Assembly Loaded Linsft.Network, 0.0.0.1
  Assembly Loaded Linsft.Storage, 0.0.0.1
  Assembly Loaded Linsft.Validator.Base, 1.0.0.22749
  Assembly Loaded System.Threading.Tasks.Dataflow, 0.0.4303.21337
  Assembly Loaded Ionic.Zip.Reduced, 1.9.1.8
  Assembly Loaded Linsft.Helper, 1.0.4845.22748
  Addin Loaded: Linsft.Core
  Idle Scheduler Initialize
  Idle Scheduler Started
  Registed new scheduler: Idle
  Starting pending task for: Idle
  Scheduler Idle loaded, unlock Initialize
  Assembly Loaded Mono.Security, 4.0.0.0
  Starting new task in default scheduler: Linsft.CommandExtensionNode: Id=Linsft.Core.Gui.InitializeGtk, Linsft.Core.Gui.GtkScheduler.Initialize()
  Addin Loaded: Linsft.Core.Gui
  Assembly Loaded atk-sharp, 3.0.0.0
  Assembly Loaded cairo-sharp, 1.10.0.0
  Assembly Loaded gdk-sharp, 3.0.0.0
  Assembly Loaded gio-sharp, 3.0.0.0
  Assembly Loaded glib-sharp, 3.0.0.0
  Assembly Loaded gtk-dotnet, 3.0.0.0
  Assembly Loaded gtk-sharp, 3.0.0.0
  Assembly Loaded pango-sharp, 3.0.0.0
  Assembly Loaded Linsft.Core.Gui, 1.0.4850.6091
  Gtk Scheduler Initialize
  Scheduler not loaded, Will be started later: Linsft.CommandExtensionNode: Id=Linsft.Core.Gui.ShowMainWindow, Scheduler=Gtk, Linsft.Core.Gui.MainWindow.ShowWindow()
  Gtk Scheduler Started
  Starting new task in default scheduler: Linsft.CommandExtensionNode: Id=Linsft.Commander.Initialize, Linsft.Commander.Terminal.Initialize()
  Addin Loaded: Linsft.Commander
  Assembly Loaded Linsft.Commander, 1.0.4852.8576
  Telnet server started: [ServicePoint: Address=tcp://127.0.0.1:8090/, ConnectionName=tcp, ConnectTimeout=15000, Port=8090]
  Registed new scheduler: Gtk
  Starting pending task for: Gtk
  Building ExtendedWindow
  Completed Building ExtendedWindow
  Building MainWindow
  Linsft.Core Opening Configuration Storage
  Opening Container, Class=Linsft.Core.Configuration, Method=.cctor
  Linsft.Core Configuration Loaded Sucessfully
  MainWindow Width=800, Height=600
  MainWindow X=65, Y=24
  Completed Building MainWindow
  Engine Initialize completed
  TcpConnectionListener Connection Request: [ServicePoint: Address=tcp://127.0.0.1:8090/, ConnectionName=tcp, ConnectTimeout=15000, Port=8090]
  Telnet client connected: [ServicePoint: Address=tcp://127.0.0.1:43544/, ConnectionName=tcp, ConnectTimeout=15000, Port=43544]
  TcpConnectionListener received a new connection: [ServicePoint: Address=tcp://127.0.0.1:43544/, ConnectionName=tcp, ConnectTimeout=15000, Port=43544]
  System.Threading.ExecutionContext doesn't implement interface System.IDisposable
  
  Stacktrace:
  
    at System.Threading.Tasks.Dataflow.Internal.Common.CreateCopyAndRun (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) &lt;0x00071&gt;
    at System.Threading.Tasks.Dataflow.Internal.Common.InvokeCallbackWithContext (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) &lt;0x0003b&gt;
    at System.Threading.Tasks.Dataflow.Internal.TargetCore`1.ProcessMessagesLoopWithExecutionContext () &lt;0x0011f&gt;
    at System.Threading.Tasks.Dataflow.Internal.TargetCore`1.&lt;ProcessAsyncIfNecessary_Slow&gt;b__3 (object) &lt;0x00033&gt;
    at System.Threading.Tasks.TaskActionInvoker/ActionObjectInvoke.Invoke (System.Threading.Tasks.Task,object,System.Threading.Tasks.Task) &lt;0x00023&gt;
    at System.Threading.Tasks.Task.InnerInvoke () &lt;0x0005c&gt;
    at System.Threading.Tasks.Task.ThreadStart () &lt;0x001cf&gt;
    at System.Threading.Tasks.Task.Execute () &lt;0x0000f&gt;
    at System.Threading.Tasks.TpScheduler.TaskExecuterCallback (object) &lt;0x0004b&gt;
    at (wrapper runtime-invoke) &lt;Module&gt;.runtime_invoke_void__this___object (object,intptr,intptr,intptr) &lt;0xffffffff&gt;
  
  Native stacktrace:
  
      mono() [0x4961e9]
      /lib/x86_64-linux-gnu/libpthread.so.0(+0xfbd0) [0x7fbd34914bd0]
      /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37) [0x7fbd34574037]
      /lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7fbd34577698]
      mono() [0x5cdd7f]
      mono() [0x5cde02]
      mono() [0x497eaf]
      mono() [0x4985c4]
      [0x41751bba]
  
  Debug info from gdb:
  
  Could not attach to process.  If your uid matches the uid of the target
  process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
  again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
  ptrace: Operation not permitted.
  No threads.
  
  =================================================================
  Got a SIGABRT while executing native code. This usually indicates
  a fatal error in the mono runtime or one of the native libraries 
  used by your application.
  =================================================================
  
  /home/madrang/WorkSpace/linsft/Source/Invensys/Build/invensys: line 5:  8910 Aborted                 (core dumped) mono "$INVENSYSDIR/Invensys.exe"
  </code></pre>
  
  <p>Running on Mono</p>
  
  <pre><code>madrang@Qosmio-X770:~$ mono --version
  Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-5ubuntu1)
  Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
      TLS:           __thread
      SIGSEGV:       altstack
      Notifications: epoll
      Architecture:  amd64
      Disabled:      none
      Misc:          softdebug 
      LLVM:          supported, not enabled.
      GC:            Included Boehm (with typed GC and Parallel Mark)
  </code></pre>
  
  <p>Any idea is welcome, as I'm now starting my second week of reading docs and code trying to find a solution to this.</p>
  
  <p>Thanks, Madrang</p>