-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Labels
area-hostingIncludes HostingIncludes HostingbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.
Milestone
Description
Repro:
WebApplicationBuilder builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
Args = args,
ApplicationName = "MySuperApp has a name that doesn't match the name of the entry assembly"
});
Now if you use any config value that should be set / overwritten by user secrets won't have these used.
This stems from
aspnetcore/src/DefaultBuilder/src/WebApplicationBuilder.cs
Lines 280 to 281 in 4a156ba
var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName)); | |
configuration.AddUserSecrets(appAssembly, optional: true, reloadOnChange: reloadOnChange); |
env.ApplicationName
which in turn is set by ApplicationName = environment?.ApplicationName ?? GetConfig(WebHostDefaults.ApplicationKey) ?? Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty; |
In order to work for every ApplicationName should the WebApplicationBuilder
be changed to
-var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
+var appAssembly = Assembly.GetEntryAssembly();
configuration.AddUserSecrets(appAssembly, optional: true, reloadOnChange: reloadOnChange);
?
Workaround: just add the user secrets manually by
if (builder.Environment.IsDevelopment())
{
builder.Configuration.AddUserSecrets<Program>(optional: true, reloadOnChange: true);
}
But it feels strange if one can set the ApplicationName, and then some things won't work as expected.
Alternatively the docs should reflect this. I prefer changing the code though.
Edit: startup fails also due to
HostingStartupAssemblies = Split(ApplicationName, GetConfig(WebHostDefaults.HostingStartupAssembliesKey)); |
That should be updated too.
Metadata
Metadata
Assignees
Labels
area-hostingIncludes HostingIncludes HostingbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.