Bug 32140

Summary: The object was used after being disposed when canceling a task that is making a network call
Product: iOS Reporter: John Miller [MSFT] <john.miller>
Component: BCL Class LibrariesAssignee: Bugzilla <bugzilla>
Severity: normal CC: dmitri.toropov, kumpera, masafa, mono-bugs+monotouch
Priority: ---    
Version: XI 8.10   
Target Milestone: Untriaged   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description John Miller [MSFT] 2015-07-20 09:27:14 UTC

   When canceling a running Task that is doing a network call, an exception is thrown: The object was used after being disposed.

**Steps to Reproduce:**

   1. Run the attached sample on an iPhone Simulator
   2. Press the only Button multiple times, quickly.

**Actual Results:**

    System.ObjectDisposedException: The object was used after being disposed.
  at System.Net.WebConnection.EndWrite (System.Net.HttpWebRequest request, Boolean throwOnError, IAsyncResult result) [0x0002c] in //Library/Frameworks/Xamarin.iOS.framework/Versions/ 
  at System.Net.WebConnectionStream.WriteAsyncCB (IAsyncResult r) [0x00013] in //Library/Frameworks/Xamarin.iOS.framework/Versions/ 

   Full stacktrace here: https://gist.github.com/therealjohn/e8128aef9ea9444e3836

**Expected Results:**

   No exceptions and the task is cancelled.

**Build Date & Platform:**

   === Xamarin Studio ===

Version 5.9.4 (build 5)
Installation UUID: e01c3049-a2d2-4e0a-aad8-afe6fb627c4d
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/johnmiller/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 8b265d6
Branch: master
Build date: 2015-06-30 15:19:13-0400

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509040005
Git revision: 8010a90f6e246b32364e3fb46ef2c9d1be9c9a2b
Build date: 2015-06-08 16:52:06-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.10.2

**Additional Information:**

   I tried to replicate this in a simpler console app (included in the soluton as "ConsoleTest"), but it was not successful so I included the iOS app. 
   Also stems from this: http://stackoverflow.com/questions/31020937/cancelling-a-task-results-in-objectdisposedexception
Comment 2 Marek Safar 2015-07-21 07:34:21 UTC

*** This bug has been marked as a duplicate of bug 31507 ***