Bug 17256 - ObjectDisposedException
Summary: ObjectDisposedException
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: master
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-01-15 15:20 UTC by Grigory (Playtika)
Modified: 2014-07-04 07:02 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Grigory (Playtika) 2014-01-15 15:20:00 UTC
System.ObjectDisposedException: The object was used after being disposed.
  at System.Threading.CancellationTokenSource.CheckDisposed () [0x00000] in <filename unknown>:0  (code.cs:1)
  at System.Threading.CancellationTokenSource.Cancel (Boolean throwOnFirstException) [0x00000] in <filename unknown>:0  (code.cs:1)
  at System.Threading.CancellationTokenSource.Cancel () [0x00000] in <filename unknown>:0  (code.cs:1)
  at System.Threading.CancellationTokenSource.<CancellationTokenSource>m__0 (System.Object token) [0x00000] in <filename unknown>:0  (code.cs:1)
  at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00000] in <filename unknown>:0  (code.cs:1)

Unfortunately i don't know exact steps to reproduce.
Comment 1 Jonathan Pryor 2014-01-15 16:07:43 UTC
Unfortunately we need a repro to do anything. :-(
Comment 2 Grigory (Playtika) 2014-01-16 09:02:45 UTC
Yeah, i understand :(

I'm looking thru code. 
HttpClient.SendAsyncWorker calls lcts.CancelAfter (timeout);
I've a feeling that issue is somewhere there. My app has big amount of HttpClient calls.

I'll try to write a repro.
Comment 3 Grigory (Playtika) 2014-01-16 09:27:50 UTC
public static void Main (string[] args)
{
	while(true)
	{	
		var c1 = new CancellationTokenSource ();
		using (c1) 
		{
			c1.CancelAfter (1);
			Thread.Sleep (1);
		}

	}

	Console.ReadLine ();
}

This code crashes on mono 3.3, but works on .NET 4.5
Comment 4 Grigory (Playtika) 2014-01-16 09:32:22 UTC
Of course mono 3.2.3 :)
Comment 5 Jonathan Pryor 2014-01-16 10:22:50 UTC
Nicely, it happens in `csharp` too:

$ MONO_OPTIONS=--debug csharp
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> using System.Threading;
csharp> while (true) { var cl = new CancellationTokenSource(); using (cl) { cl.CancelAfter(1); Thread.Sleep(1); } }

Stack trace:

> Unhandled Exception:
> System.ObjectDisposedException: The object was used after being disposed.
>   at System.Threading.CancellationTokenSource.CheckDisposed () [0x0000b] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Threading/CancellationTokenSource.cs:239 
>   at System.Threading.CancellationTokenSource.Cancel (Boolean throwOnFirstException) [0x00000] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Threading/CancellationTokenSource.cs:120 
>   at System.Threading.CancellationTokenSource.Cancel () [0x00000] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Threading/CancellationTokenSource.cs:114 
>   at System.Threading.CancellationTokenSource.<CancellationTokenSource>m__41 (System.Object token) [0x00007] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Threading/CancellationTokenSource.cs:64 
>   at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00007] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Threading/Timer.cs:317
Comment 6 Marek Safar 2014-01-17 15:04:55 UTC
Fixed in master
Comment 7 Fabien Molinet 2014-03-31 10:51:28 UTC
Hi Marek,

In which Xamarin.iOS is this fix included?
I seem to be running this issue too. Here is my stacktrace:
System.ObjectDisposedException: The object was used after being disposed.
at System.Threading.CancellationTokenSource.CheckDisposed () [0x00000] in :0 
at System.Threading.CancellationTokenSource.Cancel (Boolean throwOnFirstException) [0x00000] in :0 
at System.Threading.CancellationTokenSource.Cancel () [0x00000] in :0 
at System.Threading.CancellationTokenSource.m__0 (System.Object token) [0x00000] in :0 
at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00000] in :0 


Cheers,
Fabien
Comment 8 Marek Safar 2014-03-31 13:19:00 UTC
The fix is included in versions 7.2.1 or better
Comment 9 Fabien Molinet 2014-04-01 10:57:31 UTC
Hi Marek,

Any idea when 7.2.1 will become stable?

Thanks.
Fabien
Comment 10 Koby 2014-07-04 07:02:05 UTC
I'm having this exact same issue on iOS 7.2.6.7