Skip to content

Fix MSB1025 error when using DistributedFileLogger (-dfl flag)#13036

Merged
YuliiaKovalova merged 2 commits intomainfrom
copilot/fix-msbuild-error-logger-null
Jan 15, 2026
Merged

Fix MSB1025 error when using DistributedFileLogger (-dfl flag)#13036
YuliiaKovalova merged 2 commits intomainfrom
copilot/fix-msbuild-error-logger-null

Conversation

Copy link
Contributor

Copilot AI commented Jan 15, 2026

Summary

Fixes the MSB1025 ArgumentNullException error that occurs when using the -dfl (distributed file logger) flag with MSBuild 18. The issue was introduced in PR #12095 where distributed logger central loggers were passed to ProjectCollection without filtering out null values.

Customer Impact

Users running msbuild -dfl on MSBuild 18/VS 2026 encounter a blocking error:

MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.ArgumentNullException: Value cannot be null. (Parameter 'logger')

This prevents builds from running when using the distributed file logger, which is commonly used for multi-node build logging. The -dfl flag worked correctly in MSBuild 17 and earlier versions.

Root Cause: When using -dfl, the DistributedLoggerRecord intentionally has a null CentralLogger (as documented in XMake.cs line 4298-4299). PR #12095 introduced code that includes these central loggers in the evaluationLoggers array without filtering nulls, causing ProjectCollection.RegisterLoggerInternal() to throw ArgumentNullException.

Regression?

Testing

Code Changes:

  1. XMake.cs (line 1396): Added .Where(l => l is not null) to filter out null central loggers from the evaluationLoggers array
  2. XMake_Tests.cs: Added regression test TestNullCentralLoggerInDistributedLoggerRecord to verify DistributedLoggerRecords with null CentralLogger don't cause exceptions

Verification:

  • ✅ New unit test TestNullCentralLoggerInDistributedLoggerRecord passes
  • ✅ Build succeeded with no warnings or errors
  • ✅ Manual testing: msbuild simple.proj -dfl -t:Build now works correctly and creates distributed log file
  • ✅ Code review found no issues
  • ✅ No security vulnerabilities detected

Risk

Low - This is a minimal, surgical fix that:

  • Only filters out null loggers, which are intentionally null for distributed file loggers
  • Does not change behavior for non-null loggers
  • Restores MSBuild 17 functionality
  • Includes regression test to prevent future breakage
Original prompt

This section details on the original issue you should resolve

<issue_title>MsBuild 18/VS 2026 MSB1025 error when using DistributedFileLogger - The 'logger' parameter cannot be null.</issue_title>
<issue_description>### Issue Description

When running msbuild -dfl i receive such error

MSBUILD : error MSB1025: podczas uruchamiania programu MSBuild wystąpił błąd wewnętrzny. System.ArgumentNullException: Parametr „logger” nie może być zerowy. w Microsoft.Build.Shared.ErrorUtilities.ThrowArgumentNull(String parameterName, String resourceName) w Microsoft.Build.Evaluation.ProjectCollection.RegisterLoggerInternal(ILogger logger) w Microsoft.Build.Evaluation.ProjectCollection.RegisterLoggers(IEnumerable1 loggers)
w Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary2 globalProperties, IEnumerable1 loggers, IEnumerable1 remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, Int32 maxNodeCount, Boolean onlyLogCriticalEvents, Boolean loadProjectsReadOnly, Boolean useAsynchronousLogging, Boolean reuseProjectRootElementCache, Boolean enableTargetOutputLogging) w Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary2 globalProperties, Dictionary2 restoreProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Boolean needToValidateProject, String schemaFile, Int32 cpuCount, Boolean multiThreaded, Boolean enableNodeReuse, TextWriter preprocessWriter, TextWriter targetsWriter, Boolean detailedSummary, ISet1 warningsAsErrors, ISet1 warningsNotAsErrors, ISet1 warningsAsMessages, Boolean enableRestore, ProfilerLogger profilerLogger, Boolean enableProfiler, Boolean interactive, ProjectIsolationMode isolateProjects, GraphBuildOptions graphBuildOptions, Boolean lowPriority, Boolean question, Boolean isTaskAndTargetItemLoggingRequired, Boolean isBuildCheckEnabled, String[] inputResultsCaches, String outputResultsCache, Boolean saveProjectResult, BuildResult& result, Boolean reportFileAccesses, String commandLine)
w Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)`

Steps to Reproduce

to reproduce i create simple .net framework console solution and i run msbuild -dfl in solution directory

Expected Behavior

Solution should build as in previous version of msbuild (17)

Actual Behavior

Blocking error
MSBUILD : error MSB1025: podczas uruchamiania programu MSBuild wystąpił błąd wewnętrzny. System.ArgumentNullException: Parametr „logger” nie może być zerowy.

Analysis

I tried to find any information in documentation about breaking changes in DistributedFileLogger but with no success.

Trying different fileLoggerParameters did not help

Switching to fileLogger works as expected

Versions & Configurations

Wersja programu MSBuild 18.0.5+e22287bf1 dla .NET Framework
18.0.5.56406

ran from C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Current\Bin\amd64\MSBuild.rsp
and
C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\MSBuild\Current\Bin\amd64\MSBuild.rsp

Windows 11 </issue_description>

<agent_instructions>Yes, this bug is very likely caused by the change in PR #12095.
Here's the problematic code introduced in src/MSBuild/XMake.cs:
csharpILogger[] evaluationLoggers =
[
// all of the loggers that are single-node only
.. loggers,
// all of the central loggers for multi-node systems. These need to be resilient to multiple calls
// to Initialize
.. distributedLoggerRecords.Select(d => d.CentralLogger)
];

projectCollection = new ProjectCollection(
globalProperties,
evaluationLoggers, // <-- now includes distributed logger central loggers
...
The problem: When you use -dfl (distributed file logger), the DistributedLoggerRecord.CentralLogger can be null. The code now blindly passes all CentralLogger values into the ProjectCollection constructor without filtering out nulls.
When ProjectCollection.RegisterLoggers() iterates over these loggers and calls RegisterLoggerInternal(), it hits:
csharpprivate void RegisterLoggerInternal(ILogger logger)
{
ErrorUtilities.VerifyThrowArgumentNull(logger); // <-- throws here when logger is null
...
}
The fix should filter out null loggers:
csharpILogger[] evaluationLoggers =
[
.. loggers,
.. distributedLoggerRecords
.Select(d => d.CentralLogger)
.Where(l => l != null) // <-- add this filter
];</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@YuliiaKovalova Hi @kkapuscinski ,

Thank you for reporting the issue! It's likely to connected to #12095 change.
We are working on the fix.

cc: @baronfel </comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@dotnet-policy-service
Copy link
Contributor

Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo.

@YuliiaKovalova
Copy link
Member

@copilot try again

@baronfel
Copy link
Member

@copilot please try again, let's see if I have permissions.

…logger

Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 15, 2026

@copilot please try again, let's see if I have permissions.

Done! The fix has been implemented in commit dcdf256.

The issue was that when using -dfl, the code was passing null central loggers to ProjectCollection, which threw ArgumentNullException. The fix filters out null loggers using .Where(l => l is not null) in XMake.cs line 1396.

I've also added a regression test TestNullCentralLoggerInDistributedLoggerRecord that verifies the fix, and manually tested with the -dfl flag to confirm it now works correctly without throwing MSB1025 error.

Copilot AI changed the title [WIP] Fix MSB1025 error in DistributedFileLogger Fix MSB1025 error when using DistributedFileLogger (-dfl flag) Jan 15, 2026
Copilot AI requested a review from baronfel January 15, 2026 16:07
Copy link
Member

@baronfel baronfel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, but I have to point out that we would not have shipped this bug if xmake.cs was nullable-enabled.

@YuliiaKovalova YuliiaKovalova marked this pull request as ready for review January 15, 2026 17:11
@YuliiaKovalova YuliiaKovalova merged commit d7c46da into main Jan 15, 2026
10 checks passed
@YuliiaKovalova YuliiaKovalova deleted the copilot/fix-msbuild-error-logger-null branch January 15, 2026 18:09
@YuliiaKovalova
Copy link
Member

/backport to vs18.0

@github-actions
Copy link
Contributor

Started backporting to vs18.0 (link to workflow run)

@YuliiaKovalova
Copy link
Member

/backport to vs18.3

@github-actions
Copy link
Contributor

Started backporting to vs18.3 (link to workflow run)

This was referenced Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MsBuild 18/VS 2026 MSB1025 error when using DistributedFileLogger - The 'logger' parameter cannot be null.

3 participants