diff --git a/src/StructuredLogger/Construction/MessageProcessor.cs b/src/StructuredLogger/Construction/MessageProcessor.cs index 9229f8a6d..2604f817a 100644 --- a/src/StructuredLogger/Construction/MessageProcessor.cs +++ b/src/StructuredLogger/Construction/MessageProcessor.cs @@ -47,7 +47,7 @@ public void Process(BuildMessageEventArgs args) } var buildEventContext = args.BuildEventContext; - if (buildEventContext.TaskId != BuildEventContext.InvalidTaskId) + if (buildEventContext != null && buildEventContext.TaskId != BuildEventContext.InvalidTaskId) { if (message.StartsWith(Strings.OutputItemsMessagePrefix, StringComparison.Ordinal)) { @@ -94,7 +94,7 @@ public void Process(BuildMessageEventArgs args) } } } - else if (buildEventContext.TargetId != BuildEventContext.InvalidTargetId) + else if (buildEventContext != null && buildEventContext.TargetId != BuildEventContext.InvalidTargetId) { if (message.StartsWith(Strings.ItemGroupIncludeMessagePrefix, StringComparison.Ordinal)) { @@ -124,7 +124,7 @@ public void Process(BuildMessageEventArgs args) return; } } - else if (buildEventContext.EvaluationId != BuildEventContext.InvalidEvaluationId) + else if (buildEventContext != null && buildEventContext.EvaluationId != BuildEventContext.InvalidEvaluationId) { } else @@ -392,7 +392,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message) var buildEventContext = args.BuildEventContext; - if (buildEventContext.TaskId > 0) + if (buildEventContext != null && buildEventContext.TaskId > 0) { parent = GetTask(args); if (parent is Task task) @@ -431,7 +431,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message) } } } - else if (buildEventContext.TargetId > 0) + else if (buildEventContext != null && buildEventContext.TargetId > 0) { parent = GetTarget(args); @@ -440,7 +440,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message) lowRelevance = true; } } - else if (buildEventContext.ProjectContextId > 0) + else if (buildEventContext != null && buildEventContext.ProjectContextId > 0) { var project = construction.GetOrAddProject(buildEventContext.ProjectContextId); parent = project; @@ -470,7 +470,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message) } } } - else if (buildEventContext.EvaluationId != -1) + else if (buildEventContext != null && buildEventContext.EvaluationId != -1) { parent = construction.EvaluationFolder; @@ -533,6 +533,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message) lowRelevance = true; } else if ( + buildEventContext != null && buildEventContext.NodeId == 0 && buildEventContext.ProjectContextId == 0 && buildEventContext.ProjectInstanceId == 0 && @@ -551,6 +552,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message) return; } else if ( + buildEventContext != null && buildEventContext.NodeId == -2 && buildEventContext.ProjectContextId == -2 && buildEventContext.ProjectInstanceId == -1)