Bug 16631 - [mdtool] Possible race condition in initialization? "System.InvalidOperationException: out of sync" during `TargetRuntime.CreateFrameworks ()`
Summary: [mdtool] Possible race condition in initialization? "System.InvalidOperation...
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: General ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: 4.2.4 (from master)
Assignee: Bugzilla
Depends on:
Reported: 2013-12-05 18:48 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2014-03-12 06:17 UTC (History)
5 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 Developer Community or GitHub 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 Brendan Zagaeski (Xamarin Team, assistant) 2013-12-05 18:48:38 UTC
Reported on behalf of a user.

## Summary
"Xamarin is configured for building project automatically after each check-in. Setup worked fine with previous version of xamarin (before Microsoft, Xamarin partnership announcement), but crashes from time to time with the latest [Xamarin.iOS] version"

## Partial output from `mdtool -v build MySolution.sln -t:Build -c:"Ad-Hoc|iPhone"`

> ERROR [2013-11-27 13:18:06Z]: Unhandled exception in SystemAssemblyService background initialisation thread.
>  System.InvalidOperationException: out of sync
>    at System.Collections.Generic.Dictionary`2+Enumerator[MonoDevelop.Core.Assemblies.TargetFrameworkMoniker,MonoDevelop.Core.Assemblies.TargetFramework].VerifyState () [0x00028] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:966 
>    at System.Collections.Generic.Dictionary`2+Enumerator[MonoDevelop.Core.Assemblies.TargetFrameworkMoniker,MonoDevelop.Core.Assemblies.TargetFramework].MoveNext () [0x00000] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:889 
>    at System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator[MonoDevelop.Core.Assemblies.TargetFrameworkMoniker,MonoDevelop.Core.Assemblies.TargetFramework].MoveNext () [0x00000] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:1199 
>    at MonoDevelop.Core.Assemblies.TargetRuntime.CreateFrameworks () [0x00068] in /Users/builder/data/lanes/monodevelop-lion-license-sync/844a84fe/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/TargetRuntime.cs:510 
>    at MonoDevelop.Core.Assemblies.TargetRuntime.RunInitialization () [0x000c4] in /Users/builder/data/lanes/monodevelop-lion-license-sync/844a84fe/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/TargetRuntime.cs:427 
>    at MonoDevelop.Core.Assemblies.TargetRuntime.BackgroundInitialize (System.Object state) [0x00035] in /Users/builder/data/lanes/monodevelop-lion-license-sync/844a84fe/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/TargetRuntime.cs:389 
>  Unhandled Exception:
>  System.NullReferenceException: Object reference not set to an instance of an object
>    at MonoDevelop.Ide.IdeVersionInfo.MonoDevelop.Core.ISystemInformationProvider.get_Description () [0x0007e] in /Users/builder/data/lanes/monodevelop-lion-license-sync/844a84fe/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeVersionInfo.cs:122 
>    at MonoDevelop.Core.SystemInformation.GetTextDescription () [0x00048] in /Users/builder/data/lanes/monodevelop-lion-license-sync/844a84fe/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/SystemInformation.cs:143 
>    at MonoDevelop.Core.LoggingService.ReportUnhandledException (System.Exception ex, Boolean willShutDown, Boolean silently, System.String tag) [0x000d7] in /Users/builder/data/lanes/monodevelop-lion-license-sync/844a84fe/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/LoggingService.cs:190 
>    at MonoDevelop.Core.LoggingService.LogFatalError (System.String message, System.Exception ex) [0x00035] in /Users/builder/data/lanes/monodevelop-lion-license-sync/844a84fe/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core/LoggingService.cs:576 
>    at MonoDevelop.Core.Assemblies.TargetRuntime.BackgroundInitialize (System.Object state) [0x00048] in /Users/builder/data/lanes/monodevelop-lion-license-sync/844a84fe/source/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Assemblies/TargetRuntime.cs:391 
>  Process 'command '/Applications/Xamarin Studio.app/Contents/MacOS/mdtool'' finished with exit value 255 (state: FAILED)
>  :buildDefault FAILED
> -----

## Additional information

Bug #5039 reported a similar "out of sync" error message, though that one happened during `MonoDevelop.Projects.BuildTool.Run()`, rather than during `BackgroundInitialize()`. It sounds like in bug #5039, the problem was a timing / race issue?

If I'm reading the error messages correctly, it looks like there could be 2 separate issues here. First the "out of sync" error happens, and then while LogFatalError() is trying to log that error a NullReferenceException happens.
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2013-12-06 21:26:47 UTC
The versions that were in use before this problem appeared were probably:
- Xamarin Studio 4.0.13
- Xamarin.iOS 7.0.2
- Mono 3.2.0

The issue is currently being seen with:
- Xamarin Studio 4.2.2
- Mono 3.2.5
- Xamarin.iOS
Comment 4 Alex Blount 2013-12-10 08:37:24 UTC
I am also seeing this exact issue on our build server.

- Xamarin Studio 4.3
- Mono 3.2.5
- Xamarin.iOS
Comment 5 vol714 2014-02-06 11:04:48 UTC
I'm seeing this in 4 out of 5 builds(!) on our Jenkins build slave, which kind of invalidates the concept of running a CI server in the first place.

- Xamarin Studio 4.2.2 (build 2)
- Mono 3.2.6
- Xamarin.iOS 
- OS X 10.9.1

So far, it has not occurred on the same machine when building from Xamarin Studio. It does occur when building from command line (like Jenkins does), though.
Comment 6 Mikayla Hutchinson [MSFT] 2014-02-06 16:45:16 UTC
I was unable to repro this, but it should have been fixed by https://github.com/mono/monodevelop/commit/c71041c19de8e32e783d22da9355e3ebb34ef34c
Comment 7 vol714 2014-02-07 02:38:56 UTC
Great, thank you! 
That fix is tagged "monodevelop-4.3.2", is that the same as the Xamarin Studio version?
Comment 8 Mikayla Hutchinson [MSFT] 2014-02-07 15:53:33 UTC
Yes it's in the 4.3.2 alpha, though it should be in 4.2.4 too, when that comes out (no ETA)
Comment 9 Sadik Ali 2014-03-12 06:17:54 UTC
I verified bellow issue on bellow environments:

XS 4.2.4 (build 23)

I have followed below steps:

1. Created "SSampleApp" iOS project.
2. Run application using below command line.

mdtool -v build /Users/mac109/Desktop/SSampleApp/SSampleApp.sln -t:Build -c:"Ad-Hoc|iPhone"

I noticed that application deployed on devices and no error generated.

Terminal Log: https://gist.github.com/Sadik1/9504151

hence I am marking this as verified.