diff --git a/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs b/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs index 01bcc724f8494..cc8a86d84e1a5 100644 --- a/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs +++ b/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs @@ -163,9 +163,10 @@ static bool IsApplicationNameArg(string arg) => arg.Equals("--applicationName", StringComparison.OrdinalIgnoreCase) || arg.Equals("/applicationName", StringComparison.OrdinalIgnoreCase); - args = args.Any(arg => IsApplicationNameArg(arg)) || assembly?.GetName().Name is null - ? args - : args.Concat(new[] { "--applicationName", assembly.GetName().Name }).ToArray(); + if (!args.Any(arg => IsApplicationNameArg(arg)) && assembly.GetName().Name is string assemblyName) + { + args = args.Concat(new[] { "--applicationName", assemblyName }).ToArray(); + } var host = hostFactory(args); return GetServiceProvider(host);