Open
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
env.ApplicationName
which in turn is set by
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
That should be updated too.