System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional.

I am using JetBrains Rider 2024.3.5 Build #RD-243.24978.27, built on February 6, 2025 on a Mac Studio 2023 M2 Ultra with 64GB RAM Sequoia 15.1, and Xcode Version 16.2 (16C5032a). 

Full exception info further below:

System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The expected physical path was '/Volumes/Projects/Checklists/Checklists/bin/Debug/net9.0-maccatalyst/Checklists.app/Contents/MonoBundle/appsettings.json'.   I have also confirmed that the file is not in that location.

 Following are the steps you can use to reproduce this issue:

  1. I have created a new C# Maui .Net 9 solution with sample data from your stock template.
  2. I added  added the Microsoft.Extensions.Configuration.Abstractions, Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Json.
  3. I then right-click on solution → Add → Configuration Files → appsettings.json File and selected the same name with the default sample data. The build action is set to None and Copy always.
  4. In MauiProgram.CreateMauiApp() I added the following lines:
  5. var built = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
    var child = built.GetChildren(); 
  6. Set a breakpoint just below the above code. 
  7. Ran the project for MacCatalyst and received the following exception:

System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The expected physical path was '/Volumes/Projects/Checklists/Checklists/bin/Debug/net9.0-maccatalyst/Checklists.app/Contents/MonoBundle/appsettings.json'.
  at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
  at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
  at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
  at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
  at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
  at Checklists.MauiProgram.CreateMauiApp() in /Volumes/Projects/Checklists/Checklists/MauiProgram.cs:line 110
  at Checklists.AppDelegate.CreateMauiApp() in /Volumes/Projects/Checklists/Checklists/Platforms/MacCatalyst/AppDelegate.cs:line 29
  at Microsoft.Maui.MauiUIApplicationDelegate.WillFinishLaunching(UIApplication application, NSDictionary launchOptions)
  at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 61
  at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 96
  at Checklists.Program.Main(String[] args) in /Volumes/Projects/Checklists/Checklists/Platforms/MacCatalyst/Program.cs:line 17

0
2 comments

Hello Kmwenyon,
 
Thank you for contacting JetBrains Support. I'm glad to work with you on this ticket. 
 
This isn’t a Rider-specific issue. The issue is Appsetting.json is not natively supported in MAUI yet. See [Enhancement] Add appsettings support · Issue #4408 · dotnet/maui for more information. 
 
You can find various ways online to work this around. The way that works for me is below:

  1. Set "Build Action" of appsetting.json to "Emebded Resources"
  2. Update the code as below:
        var asm = Assembly.GetExecutingAssembly();
        var path = $"{asm.GetName().Name}.appsettings.json";
        using Stream stream = asm.GetManifestResourceStream(path);
        var built = new ConfigurationBuilder().AddJsonStream(stream).Build();
        var child = built.GetChildren(); 

 
For additional context, see this StackOverflow issue that demonstrates this pattern in MAUI environments.
 
Let me know if you have any other questions. 

Regards,

Tom
 

0

Please sign in to leave a comment.