From ee8740a4e1b809e2e02d90fa76862f3a345e7c15 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:11:06 -0500 Subject: [PATCH] [release/9.0.1xx] [XC] Fix passing message arguments to BuildException when logging warning as error (#25326) * Fix passing message args to BuildException in XamlCTask * Avoid using string.Format with null args --------- Co-authored-by: Simon Rozsival --- src/Controls/src/Build.Tasks/BuildException.cs | 7 ++++++- src/Controls/src/Build.Tasks/XamlCTask.cs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Build.Tasks/BuildException.cs b/src/Controls/src/Build.Tasks/BuildException.cs index e54f266069bd..b763e28d0160 100644 --- a/src/Controls/src/Build.Tasks/BuildException.cs +++ b/src/Controls/src/Build.Tasks/BuildException.cs @@ -30,7 +30,12 @@ protected BuildException(System.Runtime.Serialization.SerializationInfo info, Sy static string FormatMessage(BuildExceptionCode code, IXmlLineInfo xmlinfo, object[] args) { - var message = string.Format(ErrorMessages.ResourceManager.GetString(code.ErrorMessageKey), args); + var message = ErrorMessages.ResourceManager.GetString(code.ErrorMessageKey); + if (args is not null) + { + message = string.Format(message, args); + } + var ecode = code.Code; var position = xmlinfo == null || !xmlinfo.HasLineInfo() ? "" : $"({xmlinfo.LineNumber},{xmlinfo.LinePosition})"; diff --git a/src/Controls/src/Build.Tasks/XamlCTask.cs b/src/Controls/src/Build.Tasks/XamlCTask.cs index 13a66bdb9b92..829d675b0399 100644 --- a/src/Controls/src/Build.Tasks/XamlCTask.cs +++ b/src/Controls/src/Build.Tasks/XamlCTask.cs @@ -99,7 +99,7 @@ public static void LogWarningOrError(this TaskLoggingHelper loggingHelper, Build { loggingHelper.LogError("XamlC", $"{code.CodePrefix}{code.CodeCode:0000}", code.HelpLink, xamlFilePath, lineNumber, linePosition, endLineNumber, endLinePosition, ErrorMessages.ResourceManager.GetString(code.ErrorMessageKey), messageArgs); LoggedErrors ??= new(); - LoggedErrors.Add(new BuildException(code, new XmlLineInfo(lineNumber, linePosition), innerException: null)); + LoggedErrors.Add(new BuildException(code, new XmlLineInfo(lineNumber, linePosition), innerException: null, messageArgs)); } else {