aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Application fails to start when setting custom ApplicationName

Open jvmlet opened this issue 1 year ago • 6 comments

@captainsafia , @gfoidl , please have a closer look at the problem @Toudahl is complaining.

Here is the problematic part in Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions

Image

The fact that the value is set by default to the entry-point assembly name, doesn't allow to treat the ApplicationName as assembly name and try loading it !!!

This is breaking change that is not even documented.

Also, even though the manager instance could be provided via DI, the PopulateDefaultParts method is internal !!! and not marked as override - I hardly understand the reason behind letting user to injects their own implementation if he can't provide his own implementation of PopulateDefaultParts method.

Please reopen and provide estimations for the fix. Thanks

Originally posted by @jvmlet in #53791

jvmlet avatar Oct 14 '24 07:10 jvmlet

It's not a breaking change, it's been that way for years. Don't set the application name because it is used as an assembly name. Use another configuration entry.

davidfowl avatar Oct 14 '24 07:10 davidfowl

It's not a breaking change, it's been that way for years. Don't set the application name because it is used as an assembly name. Use another configuration entry.

It's been so long, so I found a different way to set an application name.

But is there an official correct way that I might have overlooked?

Toudahl avatar Oct 14 '24 07:10 Toudahl

Thanks for the quick response, @davidfowl , but with dotnet 6 things are working as expected. Also, using the standard application name entry has advantage of being picked up by other libraries, like OTEL when publishing logs, metrics and actions. Using another entry will break this.

jvmlet avatar Oct 14 '24 07:10 jvmlet

Don't set the application name because it is used as an assembly name.

This is not true, have a look at documentation comments. The fact that the value is set by default to the entry-point assembly name, doesn't allow to treat the ApplicationName as assembly name and try loading it !!!

jvmlet avatar Oct 14 '24 07:10 jvmlet

https://github.com/dotnet/aspnetcore/issues/7315

davidfowl avatar Oct 14 '24 07:10 davidfowl

@davidfowl , have you read the issue ? I'm setting custom ApplicationName with below code which works with dontnet 6 but fails with 8 because dotnet8 treats ApplicationName value as assembly name and tries to load it (MyCustomApplicationName):

.ConfigureAppConfiguration((ctx, b) => {
         ctx.HostingEnvironment.ApplicationName = "MyCustomApplicationName";
           })

jvmlet avatar Oct 14 '24 07:10 jvmlet

It's been so long, so I found a different way to set an application name.

What solution have you gone for?

sebdesalvador avatar Aug 20 '25 16:08 sebdesalvador

It's been so long, so I found a different way to set an application name.

What solution have you gone for?

I simply set it after creating the builder. So far it seems it didn't break anything.

var builder = WebApplication.CreateBuilder(args); builder.Environment.ApplicationName = "awesome-app";

Toudahl avatar Aug 20 '25 16:08 Toudahl

It's been so long, so I found a different way to set an application name.

What solution have you gone for?

I simply set it after creating the builder. So far it seems it didn't break anything.

var builder = WebApplication.CreateBuilder(args); builder.Environment.ApplicationName = "awesome-app";

I think it won't work for me, later I use AddControllers() which eventually gets to the problematic part mentionned at the beginning of this post. Thank you for your answer however, much appreciated :)

sebdesalvador avatar Aug 21 '25 06:08 sebdesalvador