diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs
index 3ebfcae6615..cc492e9b4ed 100644
--- a/src/MSBuild.UnitTests/XMake_Tests.cs
+++ b/src/MSBuild.UnitTests/XMake_Tests.cs
@@ -2294,6 +2294,44 @@ public void TestProcessFileLoggerSwitch5()
distributedLoggerRecords.Count.ShouldBe(0); // "Expected no distributed loggers to be attached"
loggers.Count.ShouldBe(0); // "Expected no central loggers to be attached"
}
+
+ ///
+ /// Verify that DistributedLoggerRecords with null CentralLogger don't cause exceptions when creating ProjectCollection
+ /// This is a regression test for the issue where -dfl flag caused MSB1025 error due to null logger not being filtered.
+ ///
+ [Fact]
+ public void TestNullCentralLoggerInDistributedLoggerRecord()
+ {
+ // Simulate the scenario when using -dfl flag
+ // ProcessDistributedFileLogger creates a DistributedLoggerRecord with null CentralLogger
+ var distributedLoggerRecords = new List();
+ bool distributedFileLogger = true;
+ string[] fileLoggerParameters = null;
+
+ MSBuildApp.ProcessDistributedFileLogger(
+ distributedFileLogger,
+ fileLoggerParameters,
+ distributedLoggerRecords);
+
+ // Verify that we have a distributed logger record with null central logger
+ distributedLoggerRecords.Count.ShouldBe(1);
+ distributedLoggerRecords[0].CentralLogger.ShouldBeNull();
+
+ // This should not throw ArgumentNullException when creating ProjectCollection
+ // The fix filters out null central loggers from the evaluationLoggers array
+ var loggers = Array.Empty();
+ Should.NotThrow(() =>
+ {
+ using var projectCollection = new ProjectCollection(
+ new Dictionary(),
+ loggers: [.. loggers, .. distributedLoggerRecords.Select(d => d.CentralLogger).Where(l => l is not null)],
+ remoteLoggers: null,
+ toolsetDefinitionLocations: ToolsetDefinitionLocations.Default,
+ maxNodeCount: 1,
+ onlyLogCriticalEvents: false,
+ loadProjectsReadOnly: true);
+ });
+ }
#endregion
#region ProcessConsoleLoggerSwitches
diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs
index 0bc9bd7aafd..181ae78179a 100644
--- a/src/MSBuild/XMake.cs
+++ b/src/MSBuild/XMake.cs
@@ -1392,8 +1392,8 @@ internal static bool BuildProject(
// 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)
+ // to Initialize. Filter out null loggers (e.g., DistributedFileLogger uses null central logger).
+ .. distributedLoggerRecords.Select(d => d.CentralLogger).Where(l => l is not null)
];
projectCollection = new ProjectCollection(