Skip to content

[Hosting][Configuration] Using Uno.Sdk + Uno.Extensions.Configuration in a Console App fails to load appsettings at runtime #3005

@DevTKSS

Description

@DevTKSS

Current behavior

In a plain .NET Console app using <Project Sdk="Uno.Sdk"> and Uno.Extensions.Configuration, configuration binding via IConfigBuilder.Section<T>() fails at runtime to resolve / load appsettings.json when I use the Microsoft HostBuilder pipeline (not the Uno HostBuilder setup usually coming from a Uno app template).

I noticed the following logic in Section<T> which looks like it relies on Uno Hosting conventions / host environment details:

static string? FilePath(HostBuilderContext hctx)
{
var file = $"{ConfigurationFolderName}/{string.Format(AppConfiguration.FileNameTemplate, typeof(TSettingsOptions).Name)}";
var appData = hctx.HostingEnvironment.GetAppDataPath();
if (appData is not { Length: > 0 })
{
return default;
}
var path = Path.Combine(appData, file);
return path;
}
return hostBuilder
.ConfigureAppConfiguration((ctx, b) =>
{
var path = FilePath(ctx);
if (path is { Length: > 0 })
{
b.AddJsonFile(path, optional: true, reloadOnChange: false); // In .NET6 we can enable this again because we can use polling
}
})
.ConfigureServices((ctx, services) =>

The Uno configuration docs/walkthrough do not mention that Hosting (UnoFeatures / Uno Hosting pipeline) is required for configuration to work, so from a user perspective Uno.Extensions.Configuration appears usable standalone.

the var appBuilder = this.CreateBuilder(e) have had not been able to get resolved, which required me to use the MS Hostbuilder CreateDefaultBuilder(args) as normal.

Expected behavior

Either:

  • Configuration docs should explicitly state that Uno.Extensions.Configuration requires Uno Hosting / <UnoFeatures>Hosting</UnoFeatures> (or the Uno host setup we usually have in Platforms/*/Programm.cs) to resolve appsettings.json correctly, or

  • Section() should work in a Console app with the Microsoft HostBuilder, as long as the JSON file is present and the configuration builder is set up correctly.

How to reproduce it (as minimally and precisely as possible)

  • The appsettings.json are located in the same level as the Programm.cs file
  • The ExcelOptions are only containing 2-3 string Values and 2 IEnumberable / string[] collections for the configured Ranges the app should be using at runtime to locate the data, so nothing special I would expect to break anything.

csproj contained UnoFeatures:

  • Configuration

  • Hosting

  • LoggingSerilog

  • Logging

  • HostBuilder used from Microsoft:

var host = Host.CreateDefaultBuilder(args)
                         .UseConfiguration(configureHostConfiguration: configurationBuilder =>
                                 configurationBuilder.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true),
                                  configure: configBuilder =>
                                   { 
                                          return configBuilder
                                                          .EmbeddedSource<Program>()
                                                                .Section<ExcelOptions>();
                                     })

Added even the File Reference as Resource, EmbeddedResource to finally get this working, without success:

<ItemGroup>
  <Resource Include="appsettings.json" CopyToOutputDirctory="CopyIfNewer" />
  <Resource Include="appsettings.Development.json" CopyToOutputDirctory="CopyIfNewer" />
</ItemGroup>

Currently not having a repro (see additional Information section) but if you can't repro without this, I can take a look to set up some Repro.

Environment

App type: Console app (Windows 10 host machine)
IDE: Visual Studio 2022 (used around Aug 2025)
TargetFramework: net9.0

Nuget Package (s):

Package Version(s): Uno.Sdk: 6.2.36/6.2.41

Affected platform(s):

  • Console App (Windows 10 Host Maschine)
  • iOS
  • macOS (AppKit)
  • Mac Catalyst
  • Android
  • WebAssembly
  • Windows
  • Skia (WPF)
  • Skia (GTK on Linux/macOS/Windows)
  • Skia (Linux Framebuffer)
  • Build tasks

Visual Studio:

  • 2019 (version: )
  • 2022 (version: ) unknown which Version this had been, this was in August 2025 🤔
  • Visual Studio Code (version: )
  • Rider Windows (version: )
  • Rider macOS (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

The Console app approach was intentional to validate .NET 8/9 compatibility of third-party/local assemblies first (UI-neutral), then later migrate to a Uno UI app by swapping the HostBuilder and reusing the net9.0 targeting modular libraries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't workingtriage/untriagedIndicates an issue requires triaging or verification.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions