Skip to content

[Http] AddRefitClient and AddKiotaClient lose the endpoint Url in trimmed builds ("BaseAddress must be set on the HttpClient instance") #3266

Open

Description

@kazo0

Current behavior

In a trimmed Release build, a Refit or Kiota client registered from an appsettings endpoint section gets no base address:

  • services.AddRefitClient<IMyApi>(context): every call throws InvalidOperationException: BaseAddress must be set on the HttpClient instance.
  • services.AddKiotaClient<MyClient>(context): the request adapter's BaseUrl is null.

The configuration section is present and correct; Debug builds and untrimmed Release builds work.

Cause. AddClientWithEndpoint binds the section with ConfigurationBinder.Get<TEndpoint> and annotates TEndpoint with [DynamicallyAccessedMembers(All)]. AddRefitClientWithEndpoint and AddKiotaClientWithEndpoint pass their own TEndpoint through without that annotation, so the requirement never reaches EndpointOptions. Since Uno.Extensions.Http became IsAotCompatible (cd3e1a6, "chore: Fix trimmer warnings", so 7.1.1 and later), TrimMode=partial trims it, and the trimmer removes the EndpointOptions.Url and UseNativeHandler setters because only reflection reaches them. The section then binds to an empty object.

The trimmer does report it (IL2091: 'TEndpoint' generic argument does not satisfy 'DynamicallyAccessedMembers' in AddRefitClientWithEndpoint), but nothing surfaces it to app developers:

  • for Refit it is folded into IL2104: Assembly 'Uno.Extensions.Http.Refit' produced trim warnings, and the Refit project runs no trim analyzer;
  • for Kiota, [RequiresUnreferencedCode] on AddKiotaClientWithEndpoint suppresses warnings in its body.

Expected behavior

The client gets the Url from its endpoint section in trimmed builds too.

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

A console app (no Uno UI needed), published trimmed in the mode iOS and Android Release builds use:

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>net10.0</TargetFramework>
  <RuntimeIdentifier>osx-arm64</RuntimeIdentifier> <!-- or win-x64, linux-x64 -->
  <SelfContained>true</SelfContained>
  <TrimMode>partial</TrimMode>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="Uno.Extensions.Http.Refit" Version="8.0.0-dev.135" />
  <PackageReference Include="Uno.Extensions.Http.Kiota" Version="8.0.0-dev.135" />
  <PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.12" />
</ItemGroup>
var host = Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration(c => c.AddInMemoryCollection(new Dictionary<string, string?>
    {
        ["DemoApi:Url"] = "http://127.0.0.1:9",
        ["DemoKiotaClient:Url"] = "http://127.0.0.1:9",
    }))
    .ConfigureServices((context, services) =>
    {
        services.AddTransient<HttpMessageHandler, HttpClientHandler>(); // what Http.UI's AddNativeHandler does
        services.AddRefitClient<IDemoApi>(context);
        services.AddKiotaClient<DemoKiotaClient>(context, name: "DemoKiotaClient");
    })
    .Build();

await host.Services.GetRequiredService<IDemoApi>().Get();               // trimmed: "BaseAddress must be set..."
Console.WriteLine(host.Services.GetRequiredService<DemoKiotaClient>().Adapter.BaseUrl); // trimmed: empty

public interface IDemoApi { [Get("/api/test")] Task<string> Get(); }
public class DemoKiotaClient(IRequestAdapter adapter) { public IRequestAdapter Adapter { get; } = adapter; }

dotnet run: Refit reaches the network (connection refused on port 9) and Kiota prints the URL. dotnet publish -p:PublishTrimmed=true and run the output: Refit throws BaseAddress must be set on the HttpClient instance, Kiota prints nothing. The trimmed Uno.Extensions.Http.dll has no set_Url / set_UseNativeHandler.

The same failure was seen in a real app: the Uno.Samples OIDC sample (unoplatform/Uno.Samples#969) on an iOS simulator built with MtouchLink=SdkOnly; adding <TrimmerRootAssembly Include="Uno.Extensions.Http" /> made it work.

Workaround until a fix ships: <ItemGroup><TrimmerRootAssembly Include="Uno.Extensions.Http" /></ItemGroup> in the app project.

Environment

Nuget Package (s): Uno.Extensions.Http.Refit, Uno.Extensions.Http.Kiota (the setters are trimmed out of Uno.Extensions.Http)

Package Version(s): 8.0.0-dev.135 (reproduced); stable 7.1.1 to 7.3.6 have the same code (Uno.Extensions.Http is IsAotCompatible, the wrappers are unannotated); 7.0.17 does not mark the assembly trimmable.

Affected platform(s): any trimmed Release build that uses AddRefitClient or AddKiotaClient with an endpoint section.

  • iOS (reproduced on the simulator with MtouchLink=SdkOnly; Release defaults to TrimMode=partial)
  • macOS (AppKit)
  • Mac Catalyst
  • Android (Release resolves PublishTrimmed=true, TrimMode=partial; not run)
  • WebAssembly (Release resolves TrimMode=full; not run)
  • Windows
  • Skia (WPF)
  • Skia (GTK on Linux/macOS/Windows)
  • Skia (Linux Framebuffer)
  • Build tasks

Skia desktop does not trim by default and is not affected.

Anything else we need to know?

Fix and a CI regression test (a console app published trimmed and run after the unit tests) are in the linked PR.

Activity

  1. added
    kind/bug
    triage/untriaged
    on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/httparea/http-kiotaarea/http-refitkind/bugtriage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions