From e86e3dab613dc1c9b7439e8609df4aec46437f10 Mon Sep 17 00:00:00 2001 From: Prakhar Londhe Date: Mon, 13 May 2024 17:21:06 +0530 Subject: [PATCH 1/2] Fixed the discrepancy between applicationName between normal app launch and HostFactoryResolver launch https://github.com/dotnet/runtime/issues/96596 --- .../src/HostFactoryResolver.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs b/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs index 1d14d29df8169..01bcc724f8494 100644 --- a/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs +++ b/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs @@ -163,9 +163,9 @@ static bool IsApplicationNameArg(string arg) => arg.Equals("--applicationName", StringComparison.OrdinalIgnoreCase) || arg.Equals("/applicationName", StringComparison.OrdinalIgnoreCase); - args = args.Any(arg => IsApplicationNameArg(arg)) || assembly.FullName is null + args = args.Any(arg => IsApplicationNameArg(arg)) || assembly?.GetName().Name is null ? args - : args.Concat(new[] { "--applicationName", assembly.FullName }).ToArray(); + : args.Concat(new[] { "--applicationName", assembly.GetName().Name }).ToArray(); var host = hostFactory(args); return GetServiceProvider(host); From 871bbe17b3f3207607adabf8db38d6dacbe5c03d Mon Sep 17 00:00:00 2001 From: Prakhar Londhe Date: Mon, 13 May 2024 17:23:35 +0530 Subject: [PATCH 2/2] Update HostFactoryResolverTests.cs --- .../tests/HostFactoryResolverTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs b/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs index f123b65bb58bc..d36d9229d3675 100644 --- a/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs +++ b/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs @@ -274,7 +274,7 @@ public void ApplicationNameSetFromArgument() IServiceProvider? serviceProvider = factory(Array.Empty()); var configuration = (IConfiguration)serviceProvider.GetService(typeof(IConfiguration)); - Assert.Contains("ApplicationNameSetFromArgument", configuration["applicationName"]); + Assert.Equal("ApplicationNameSetFromArgument", configuration["applicationName"]); } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupportedOrBrowserBackgroundExec))]