From 949f33227f2913369b671be18611df64cf34c907 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 14 May 2020 22:00:49 +0200 Subject: [PATCH] Unwrap TargetInvocationException. To provide a better error message to the designer. --- .../Remote/RemoteDesignerEntryPoint.cs | 10 +------- .../DesignMessages.cs | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs index 44d9a94f5a..e61fe82c41 100644 --- a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs +++ b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs @@ -234,18 +234,10 @@ namespace Avalonia.DesignerSupport.Remote } catch (Exception e) { - var xmlException = e as XmlException; - s_transport.Send(new UpdateXamlResultMessage { Error = e.ToString(), - Exception = new ExceptionDetails - { - ExceptionType = e.GetType().FullName, - Message = e.Message.ToString(), - LineNumber = xmlException?.LineNumber, - LinePosition = xmlException?.LinePosition, - } + Exception = new ExceptionDetails(e), }); } } diff --git a/src/Avalonia.Remote.Protocol/DesignMessages.cs b/src/Avalonia.Remote.Protocol/DesignMessages.cs index 5ff16c574d..5c769ad48c 100644 --- a/src/Avalonia.Remote.Protocol/DesignMessages.cs +++ b/src/Avalonia.Remote.Protocol/DesignMessages.cs @@ -1,4 +1,7 @@ using System; +using System.Reflection; +using System.Runtime.ExceptionServices; +using System.Xml; namespace Avalonia.Remote.Protocol.Designer { @@ -26,6 +29,27 @@ namespace Avalonia.Remote.Protocol.Designer public class ExceptionDetails { + public ExceptionDetails() + { + } + + public ExceptionDetails(Exception e) + { + if (e is TargetInvocationException) + { + e = e.InnerException; + } + + ExceptionType = e.GetType().Name; + Message = e.Message; + + if (e is XmlException xml) + { + LineNumber = xml.LineNumber; + LinePosition = xml.LinePosition; + } + } + public string ExceptionType { get; set; } public string Message { get; set; } public int? LineNumber { get; set; }