Bug 35828 - Thread.CurrentThread doesn't return correct object in appdomain
Summary: Thread.CurrentThread doesn't return correct object in appdomain
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 4.2.0 (C6)
Hardware: PC Mac OS
: --- normal
Target Milestone: (C6SR1)
Assignee: Ludovic Henry
: 39178 ()
Depends on:
Reported: 2015-11-12 22:21 UTC by Zoltan Varga
Modified: 2016-02-29 15:54 UTC (History)
9 users (show)

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:

Description Zoltan Varga 2015-11-12 22:21:45 UTC
Reproducible in 4.2/master.

using System;
using System.Threading;

public class WorkStateThread
public void Start()
m_thread = new Thread(ThreadProc);

private void ThreadProc (object objData)
if (m_thread != Thread.CurrentThread)
throw new InvalidOperationException ("m_thread != Thread.CurrentThread");

Thread m_thread;

class MainClass
	public void foo () {
		WorkStateThread ws = new WorkStateThread ();
		ws.Start ();
		Console.WriteLine ("Done");

	public static void Main (string[] args) {
		AppDomain ad = AppDomain.CreateDomain ("foo");
		var o = new MainClass ();
		ad.DoCallBack (o.foo);
Comment 1 Alexis Christoforides 2015-11-13 17:44:01 UTC
This might be a related: https://bugzilla.xamarin.com/show_bug.cgi?id=35530
Comment 2 Zoltan Varga 2015-11-15 08:33:39 UTC
Fixed in mono master ea09193eb876a2020cb3e0ae72138b5f73774c06.
Comment 3 Martin Potter 2015-11-16 14:24:24 UTC
Thank you for fixing this quickly. Was this fix going to make its way into the 4.2 release (or is 4.2 shipping off of master)?
Comment 4 Rodrigo Kumpera 2015-11-16 14:25:43 UTC
We should schedule this bug for C6
Comment 5 Udham Singh 2015-11-24 13:42:29 UTC
I have checked this issue with latest master mono MonoFramework-MDK- with the help of code provided in bug description, and observed that the value of m_thread is equal to Thread.CurrentThread with this build.

I have also checked this with Cycle 6 mono MonoFramework-MDK- and with this I observed that value of m_thread is not equal to Thread.CurrentThread.

Screencast : http://www.screencast.com/t/W9cMfseGjkC

As of now I am closing this issue. Please let me know if I have to check something else.

Environment Info : 

=== Xamarin Studio ===

Version 5.10 (build 871)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
	Mono 4.3.0 (master/f82f4e8)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 403002163

=== Xamarin.Profiler ===

Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/xamarin76/Desktop/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.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23

Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: 0.3.7
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 7.1 (9079)
Build 7B91b

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: ac3fe9a
Branch: master
Build date: 2015-11-22 15:06:07-0500

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 510000871
Git revision: 4e9c5abb5ffdae12ba02ac49da83f8b2011dbb88
Build date: 2015-11-12 06:02:54-05
Xamarin addins: 55007ed0e56436f385d8e26394a45be563abc7e8
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5
Darwin Xamarin76s-Mac-mini.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2015-12-08 23:40:12 UTC
## Status update for any users CC'd on the bug

The candidate fix for this issue is not yet included in the preliminary Alpha version of "Cycle 6 – Service Release 1" published today, but that is mostly because those builds are still just early Alpha versions. The candidate fix will likely be included in a future preview version of "Cycle 6 – Service Release 1."
Comment 7 Ludovic Henry 2016-02-29 15:54:14 UTC
*** Bug 39178 has been marked as a duplicate of this bug. ***