c#: Mac application runs perfectly in visual studio, yet when the executable runs it throws NullReferenceException. File reading issue?

I have written a c# application in Visual Studio (using Avalonia, irrelevant for this question).

It runs perfectly in Visual Studio, Yet when I try and run the executable it throws a NullReference Exception. I have added error checking to find out the error is based on the reading of my settings.json file.

For now, I have placed the settings file in “Documents/ContactFinder/Settings.json”

Essentially when the application starts, it runs my initLoader method which contains this code:

public void initLoader()
    {
        string docs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        string path = Path.Combine(docs, "ContactFinder");
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        string settingsPath = Path.Combine(path, "settings.json");
        if (!File.Exists(settingsPath))
        {
            Settings set = new Settings();
            set.restoreDefaults();
            File.WriteAllText(settingsPath, JsonConvert.SerializeObject(set));
        }
    }

Then it calls LoadSettings, which then also pushes the settings to the application as follows:

public void LoadSettings()
    {
        try
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/ContactFinder/settings.json";
            if (!File.Exists(path))
            {
                Console.WriteLine("Settings file not found: " + path);
                throw new FileNotFoundException("Settings file not found", path);
            }

            string json = File.ReadAllText(path);
            Console.WriteLine("Settings file content: " + json);

            Settings set = JsonConvert.DeserializeObject<Settings>(json);
            pushSettings(set);
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error loading settings: {ex.Message}");
            throw;
        }
    }

public void pushSettings(Settings set)
    {
        if (set == null)
        {
            throw new ArgumentNullException(nameof(set), "Settings object is null");
        }
        ShortPMin = set.pauses.ShortPause.min.ToString();
        ShortPMax = set.pauses.ShortPause.max.ToString();
        MedPMin = set.pauses.MediumPause.min.ToString();
        MedPMax = set.pauses.MediumPause.max.ToString();
        MtlPMin = set.pauses.MtlPause.min.ToString();
        MtlPMax = set.pauses.MtlPause.max.ToString();
        LongPMin = set.pauses.LongPause.min.ToString();
        LongPMax = set.pauses.LongPause.max.ToString();
        PagePMin = set.pauses.PageLoad.min.ToString();
        PagePMax = set.pauses.PageLoad.max.ToString();
        SbEnabled = set.browser?.showBrowser ?? false;
        Users.Clear();
        if (set.logins.users != null)
        {
            foreach (var user in set.logins.users)
            {
                Users.Add(new LoginUsers(user.username, user.password));
            }
        }
        DefaultPages = set.search.defaultPageCount;
        bPages = DefaultPages;
        SelectedUser = Users.FirstOrDefault();
    }

Each of the variables set in the PushSettings method are bindings to the View, and all the previous methods listed are in the MainViewModel.cs

when I start debugging in visual studio it runs perfectly, outputs the contents of settings file to console. Pushes the settings to the app and it starts fine.

Here is how i attempt to start the application on Mac, for reference I am on Arm64. The error is shown here also

thomas@thomass-Mac-mini publish % chmod +x testMacArm642
thomas@thomass-Mac-mini publish % sudo ./testMacArm642
Password:
Settings file content: 
Error loading settings: Settings object is null (Parameter 'set')
Unhandled exception. System.ArgumentNullException: Settings object is null (Parameter 'set')
   at testMacArm642.ViewModels.MainWindowViewModel.pushSettings(Settings set) in /Users/thomas/Projects/testMacArm642/testMacArm642/ViewModels/MainWindowViewModel.cs:line 462
   at testMacArm642.ViewModels.MainWindowViewModel.LoadSettings() in /Users/thomas/Projects/testMacArm642/testMacArm642/ViewModels/MainWindowViewModel.cs:line 503
   at testMacArm642.ViewModels.MainWindowViewModel..ctor() in /Users/thomas/Projects/testMacArm642/testMacArm642/ViewModels/MainWindowViewModel.cs:line 407
   at testMacArm642.App.OnFrameworkInitializationCompleted() in /Users/thomas/Projects/testMacArm642/testMacArm642/App.axaml.cs:line 20
   at Avalonia.AppBuilder.SetupUnsafe()
   at Avalonia.AppBuilder.Setup()
   at Avalonia.AppBuilder.SetupWithLifetime(IApplicationLifetime lifetime)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder)
   at testMacArm642.Program.Main(String[] args) in /Users/thomas/Projects/testMacArm642/testMacArm642/Program.cs:line 13
zsh: abort      sudo ./testMacArm642
thomas@thomass-Mac-mini publish % 

what can i do to allow the application to read the settings file properly and load it into the program?

Thanks

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật