Skip to content

Commit

Permalink
[release/9.0.1xx] [XC] Fix passing message arguments to BuildExceptio…
Browse files Browse the repository at this point in the history
…n 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 <[email protected]>
  • Loading branch information
github-actions[bot] and simonrozsival authored Oct 18, 2024
1 parent f5ca66a commit ee8740a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Controls/src/Build.Tasks/BuildException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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})";

Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Build.Tasks/XamlCTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit ee8740a

Please sign in to comment.