From e462e3f6b8e41a06a449f01dec8929b13ec1c775 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Wed, 17 Jul 2024 21:04:29 +0200 Subject: [PATCH 1/2] Bypass logcontext validity check --- src/Build/BackEnd/Components/Logging/TargetLoggingContext.cs | 4 ++-- .../BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Build/BackEnd/Components/Logging/TargetLoggingContext.cs b/src/Build/BackEnd/Components/Logging/TargetLoggingContext.cs index af37bd0f690..4e796bfa932 100644 --- a/src/Build/BackEnd/Components/Logging/TargetLoggingContext.cs +++ b/src/Build/BackEnd/Components/Logging/TargetLoggingContext.cs @@ -91,7 +91,7 @@ internal ProjectTargetInstance Target /// internal void LogTargetBatchFinished(string projectFullPath, bool success, IEnumerable targetOutputs) { - ErrorUtilities.VerifyThrow(IsValid, "Should be valid"); + this.CheckValidity(); TargetOutputItemsInstanceEnumeratorProxy targetOutputWrapper = null; @@ -110,7 +110,7 @@ internal void LogTargetBatchFinished(string projectFullPath, bool success, IEnum /// internal TaskLoggingContext LogTaskBatchStarted(string projectFullPath, ProjectTargetInstanceChild task, string taskAssemblyLocation) { - ErrorUtilities.VerifyThrow(IsValid, "Should be valid"); + this.CheckValidity(); return new TaskLoggingContext(this, projectFullPath, task, taskAssemblyLocation); } diff --git a/src/Build/BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs b/src/Build/BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs index 14150696614..c1637420863 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs @@ -171,7 +171,8 @@ private void CurrentDomainOnAssemblyLoad(object? sender, AssemblyLoadEventArgs a if (_loggingContext?.BuildEventContext != null) { buildArgs.BuildEventContext = _loggingContext.BuildEventContext; - _loggingContext.LogBuildEvent(buildArgs); + // bypass the logging context validity check + _loggingContext.LoggingService.LogBuildEvent(buildArgs); } _loggingService?.LogBuildEvent(buildArgs); } From 0b49e9d5be7f68a4586963a9139898a93fe5b3a5 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Thu, 18 Jul 2024 08:12:28 +0200 Subject: [PATCH 2/2] Update from PR comments Co-authored-by: Rainer Sigwald --- .../BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Build/BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs b/src/Build/BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs index c1637420863..8835f4278ca 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/AssemblyLoadsTracker.cs @@ -171,7 +171,8 @@ private void CurrentDomainOnAssemblyLoad(object? sender, AssemblyLoadEventArgs a if (_loggingContext?.BuildEventContext != null) { buildArgs.BuildEventContext = _loggingContext.BuildEventContext; - // bypass the logging context validity check + // bypass the logging context validity check: it's possible that the load happened + // on a thread unrelated to the context we're tracking loads in _loggingContext.LoggingService.LogBuildEvent(buildArgs); } _loggingService?.LogBuildEvent(buildArgs);