浏览代码

Log meaningful message for AggregateException.

Steven Kirk 9 年之前
父节点
当前提交
92ebb7f6d8

+ 1 - 1
src/Avalonia.Base/AvaloniaObject.cs

@@ -670,7 +670,7 @@ namespace Avalonia
                         "Error binding to {Target}.{Property}: {Message}",
                         this,
                         property,
-                        notification.Error.Message);
+                        ExceptionUtilities.GetMessage(notification.Error));
                 }
             }
         }

+ 23 - 0
src/Avalonia.Base/Utilities/ExceptionUtilities.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Avalonia.Utilities
+{
+    internal static class ExceptionUtilities
+    {
+        public static string GetMessage(Exception e)
+        {
+            var aggregate = e as AggregateException;
+
+            if (aggregate != null)
+            {
+                return string.Join(" | ", aggregate.InnerExceptions.Select(x => x.Message));
+            }
+
+            return e.Message;
+        }
+    }
+}

+ 2 - 1
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ControlBindingTests.cs

@@ -43,7 +43,8 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
                     pv.Length == 3 &&
                     pv[0] is ProgressBar &&
                     object.ReferenceEquals(pv[1], ProgressBar.ValueProperty) &&
-                    (string)pv[2] == "Could not convert FallbackValue 'bar' to 'System.Double'")
+                    (string)pv[2] == "Object reference not set to an instance of an object. | " + 
+                                     "Could not convert FallbackValue 'bar' to 'System.Double'")
                 {
                     called = true;
                 }