From 542dc56dadb8af0e67b711604cef37d3f5500eb9 Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Tue, 12 May 2026 11:23:36 -0400 Subject: [PATCH] Fix ArgumentNullException in AppleSdkSettings when no settings file exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The static constructor iterates over SettingsPathCandidates looking for an existing settings file (maui/Settings.plist or Xamarin/Settings.plist). When neither file exists — which happens on fresh machines or CI agents that have never configured an Xcode path — SettingsPath remains null. This causes Directory.CreateDirectory(Path.GetDirectoryName(null)) to throw System.ArgumentNullException at line 145 (parameter 'path'), which propagates as a TypeInitializationException and ultimately fails the DetectSdkLocations MSBuild task, breaking all builds. Fix: after the loop, if no existing settings file was found, default SettingsPath to the first candidate (~/Library/Preferences/maui/Settings.plist). This ensures the directory is created and Init() can proceed to discover Xcode via xcode-select or other fallback mechanisms. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Xamarin.MacDev/AppleSdkSettings.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Xamarin.MacDev/AppleSdkSettings.cs b/Xamarin.MacDev/AppleSdkSettings.cs index 749a0f0..8262df3 100644 --- a/Xamarin.MacDev/AppleSdkSettings.cs +++ b/Xamarin.MacDev/AppleSdkSettings.cs @@ -28,6 +28,7 @@ using System.ComponentModel; using System.Diagnostics; using System.IO; +using System.Linq; // Disable until we get around to enable + fix any issues. #nullable disable @@ -142,6 +143,10 @@ static AppleSdkSettings () break; } + // If no existing settings file was found, default to the first candidate path. + if (SettingsPath is null) + SettingsPath = XcodeLocator.SettingsPathCandidates.First (); + Directory.CreateDirectory (Path.GetDirectoryName (SettingsPath)); Init ();