Merge pull request #820 from brendanzagaeski/master
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / ConsoleLogger.cs
index 5e6e8b54e4a6e04d8b48a2e7e4d0933d159ce40d..5fb7d21899cb771de2ce7d34dfded611aebfc06e 100644 (file)
@@ -279,14 +279,26 @@ namespace Microsoft.Build.BuildEngine
                
                Dictionary<object,BuildRecord> build_records = new Dictionary<object, BuildRecord> ();
                
+               object dummy_key = new object ();
+               
                BuildRecord GetBuildRecord (object sender)
                {
-                       if (sender == null)
-                               throw new ArgumentNullException ("sender");
                        BuildRecord r;
-                       if (!build_records.TryGetValue (sender, out r)) {
+                       // FIXME: our Microsoft.Build.Engine shouldn't give different "sender" object for each event
+                       // during the same build run. But it actually does.
+                       // It is problematic for parallel build because it is impossible to determine right "ongoing build"
+                       // record for the event without correct sender object.
+                       // Hence we expect sender as a valid object only if it is IBuildEngine4 -
+                       // only Microsoft.Build.Internal.BuildEngine4 implements it so far. 
+                       // (Used IBuildEngine3 because it needs to build for NET_4_0).
+#if NET_4_0
+                       var key = sender as IBuildEngine3 ?? dummy_key;
+#else
+                       var key = dummy_key;
+#endif
+                       if (!build_records.TryGetValue (key, out r)) {
                                r = new BuildRecord (this);
-                               build_records.Add (sender, r);
+                               build_records.Add (key, r);
                        }
                        return r;
                }