From a9c95b737d674be219ca37586d69145eaa6e6b77 Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Fri, 31 Jul 2026 21:45:48 +0200 Subject: [PATCH 1/6] Fix Environment.GetCommandLineArgs()[0] --- .../design/features/host-runtime-information.md | 4 ++++ src/coreclr/hosts/corerun/corerun.cpp | 17 +++++++++++++++++ src/coreclr/vm/corhost.cpp | 15 +++++++-------- .../tests/Assets/Projects/HelloWorld/Program.cs | 7 +++++++ .../tests/HostActivation.Tests/SymbolicLinks.cs | 7 +++++-- src/native/corehost/host_runtime_contract.h | 1 + src/native/corehost/hostpolicy/args.cpp | 3 +++ src/native/corehost/hostpolicy/args.h | 1 + .../corehost/hostpolicy/hostpolicy_context.cpp | 9 +++++++++ .../corehost/hostpolicy/hostpolicy_context.h | 1 + 10 files changed, 55 insertions(+), 10 deletions(-) diff --git a/docs/design/features/host-runtime-information.md b/docs/design/features/host-runtime-information.md index 7140bb0f658e39..8d25000ae46e3b 100644 --- a/docs/design/features/host-runtime-information.md +++ b/docs/design/features/host-runtime-information.md @@ -40,6 +40,10 @@ Directory containing the application. This is used for [`AppContext.BaseDirector [Runtime identifier](https://learn.microsoft.com/dotnet/core/rid-catalog) for the application. This is used for [`RuntimeInformation.RuntimeIdentifier`](https://learn.microsoft.com/dotnet/api/system.runtime.interopservices.runtimeinformation.runtimeidentifier). +`HOST_INVOCATION_NAME` + +The name used to invoke the host, corresponding to the native process's `argv[0]`. This is used for the first element returned by [`Environment.GetCommandLineArgs()`](https://learn.microsoft.com/dotnet/api/system.environment.getcommandlineargs). + ### Deps files `APP_CONTEXT_DEPS_FILES` diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index 3ab04343b8a052..1de42c3bb9e42a 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -57,6 +57,9 @@ struct configuration // The full path to the Supplied managed entry assembly. string_t entry_assembly_fullpath; + // The name used to invoke corerun. + string_t invocation_name; + // Arguments to pass to managed entry assembly. int entry_assembly_argc; const char_t** entry_assembly_argv; @@ -279,6 +282,18 @@ size_t HOST_CONTRACT_CALLTYPE get_runtime_property( return len; } + if (::strcmp(key, HOST_PROPERTY_INVOCATION_NAME) == 0) + { + pal::string_utf8_t value_utf8 = pal::convert_to_utf8(config->invocation_name.c_str()); + size_t len = value_utf8.size() + 1; + if (value_buffer_size < len) + return len; + + ::strncpy(value_buffer, value_utf8.c_str(), len - 1); + value_buffer[len - 1] = '\0'; + return len; + } + // Look up user-defined properties passed to corerun via -p/--property. assert(config->user_defined_keys.size() == config->user_defined_values.size()); pal::string_t key_native = pal::convert_from_utf8(key); @@ -736,6 +751,8 @@ static bool parse_args( return false; } + config.invocation_name = argv[0]; + for (int i = 1; i < argc; i++) { bool is_option = pal::is_cli_option(argv[i][0]); diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index e7c525050bd8e0..fd0b665aad1101 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -37,6 +37,7 @@ #endif // !TARGET_UNIX #include "nativelibrary.h" +#include "hostinformation.h" #ifndef DACCESS_COMPILE @@ -220,14 +221,9 @@ HRESULT CorHost2::ExecuteApplication(LPCWSTR pwzAppFullName, * This method processes the arguments sent to the host which are then used * to invoke the main method. * Note - - * [0] - points to the assemblyName that has been sent by the host. + * [0] - points to the native invocation name provided by the host. If the host + * does not provide one, it points to the assembly name that was sent by the host. * The rest are the arguments sent to the assembly. - * Also note, this might not always return the exact same identity as the cmdLine - * used to invoke the method. - * - * For example :- - * ActualCmdLine - Foo arg1 arg2. - * (Host1) - Full_path_to_Foo arg1 arg2 */ static PTRARRAYREF SetCommandLineArgs(PCWSTR pwzAssemblyPath, int argc, PCWSTR* argv) { @@ -242,7 +238,10 @@ static PTRARRAYREF SetCommandLineArgs(PCWSTR pwzAssemblyPath, int argc, PCWSTR* // Record the command line. SaveManagedCommandLine(pwzAssemblyPath, argc, argv); - PCWSTR exePath = Bundle::AppIsBundle() ? static_cast(Bundle::AppBundle->Path()) : pwzAssemblyPath; + StackSString invocationName; + PCWSTR exePath = HostInformation::GetProperty(HOST_PROPERTY_INVOCATION_NAME, invocationName) + ? invocationName.GetUnicode() + : (Bundle::AppIsBundle() ? static_cast(Bundle::AppBundle->Path()) : pwzAssemblyPath); PTRARRAYREF result = NULL; GCPROTECT_BEGIN(result); diff --git a/src/installer/tests/Assets/Projects/HelloWorld/Program.cs b/src/installer/tests/Assets/Projects/HelloWorld/Program.cs index 7fd61b604c4c04..d13ef9c5a7e745 100644 --- a/src/installer/tests/Assets/Projects/HelloWorld/Program.cs +++ b/src/installer/tests/Assets/Projects/HelloWorld/Program.cs @@ -52,6 +52,13 @@ public static void Main(string[] args) Console.WriteLine($"AppContext.GetData({propertyName}) = {propertyValue}"); } break; + case "print_command_line_args": + string[] commandLineArgs = Environment.GetCommandLineArgs(); + for (int i = 0; i < commandLineArgs.Length; i++) + { + Console.WriteLine($"Environment.GetCommandLineArgs()[{i}] = {commandLineArgs[i]}"); + } + break; case "throw_exception": // Disable core dumps - test is intentionally crashing Utilities.CoreDump.Disable(); diff --git a/src/installer/tests/HostActivation.Tests/SymbolicLinks.cs b/src/installer/tests/HostActivation.Tests/SymbolicLinks.cs index a80d9c9e014e90..0740a312e391b0 100644 --- a/src/installer/tests/HostActivation.Tests/SymbolicLinks.cs +++ b/src/installer/tests/HostActivation.Tests/SymbolicLinks.cs @@ -43,7 +43,8 @@ public void Symlink_all_files_fx(string symlinkRelativePath) symlinks.Add(new SymLink(symlinkPath, file)); } - var result = Command.Create(Path.Combine(testDir.Location, symlinkRelativePath, Path.GetFileName(sharedTestState.FrameworkDependentApp.AppExe))) + string appHostPath = Path.Combine(testDir.Location, symlinkRelativePath, Path.GetFileName(sharedTestState.FrameworkDependentApp.AppExe)); + var result = Command.Create(appHostPath, "print_command_line_args") .CaptureStdErr() .CaptureStdOut() .DotNetRoot(HostTestContext.BuiltDotNet.BinPath) @@ -54,7 +55,9 @@ public void Symlink_all_files_fx(string symlinkRelativePath) // * Unix: The apphost will look next to the resolved apphost for the app dll and find the real thing result .Should().Pass() - .And.HaveStdOutContaining("Hello World"); + .And.HaveStdOutContaining("Hello World") + .And.HaveStdOutContaining($"Environment.GetCommandLineArgs()[0] = {appHostPath}") + .And.HaveStdOutContaining("Environment.GetCommandLineArgs()[1] = print_command_line_args"); } finally { diff --git a/src/native/corehost/host_runtime_contract.h b/src/native/corehost/host_runtime_contract.h index 9bfea43f168c44..7d149fe8b774c0 100644 --- a/src/native/corehost/host_runtime_contract.h +++ b/src/native/corehost/host_runtime_contract.h @@ -19,6 +19,7 @@ #define HOST_PROPERTY_BUNDLE_PROBE "BUNDLE_PROBE" #define HOST_PROPERTY_BUNDLE_EXTRACTION_PATH "BUNDLE_EXTRACTION_PATH" #define HOST_PROPERTY_ENTRY_ASSEMBLY_NAME "ENTRY_ASSEMBLY_NAME" +#define HOST_PROPERTY_INVOCATION_NAME "HOST_INVOCATION_NAME" #define HOST_PROPERTY_NATIVE_DLL_SEARCH_DIRECTORIES "NATIVE_DLL_SEARCH_DIRECTORIES" #define HOST_PROPERTY_PINVOKE_OVERRIDE "PINVOKE_OVERRIDE" #define HOST_PROPERTY_PLATFORM_RESOURCE_ROOTS "PLATFORM_RESOURCE_ROOTS" diff --git a/src/native/corehost/hostpolicy/args.cpp b/src/native/corehost/hostpolicy/args.cpp index 4c64ebde2a1d37..dab162ff86c981 100644 --- a/src/native/corehost/hostpolicy/args.cpp +++ b/src/native/corehost/hostpolicy/args.cpp @@ -20,6 +20,9 @@ bool parse_arguments( const int argc, const pal::char_t* argv[], arguments_t& args) { + if (argc > 0) + args.invocation_name = argv[0]; + pal::string_t managed_application_path; if (init.host_mode == host_mode_t::apphost) { diff --git a/src/native/corehost/hostpolicy/args.h b/src/native/corehost/hostpolicy/args.h index e13edd4a4f7ca8..0539e7e3d1edc4 100644 --- a/src/native/corehost/hostpolicy/args.h +++ b/src/native/corehost/hostpolicy/args.h @@ -126,6 +126,7 @@ struct arguments_t host_mode_t host_mode; pal::string_t app_root; pal::string_t deps_path; + pal::string_t invocation_name; pal::string_t managed_application; int app_argc; diff --git a/src/native/corehost/hostpolicy/hostpolicy_context.cpp b/src/native/corehost/hostpolicy/hostpolicy_context.cpp index d1285d5221b81c..6498a49c952854 100644 --- a/src/native/corehost/hostpolicy/hostpolicy_context.cpp +++ b/src/native/corehost/hostpolicy/hostpolicy_context.cpp @@ -122,6 +122,14 @@ namespace return pal::pal_utf8string(get_filename_without_ext(context->application), value_buffer, value_buffer_size); } + if (::strcmp(key, HOST_PROPERTY_INVOCATION_NAME) == 0) + { + if (context->host_mode == host_mode_t::libhost) + return -1; + + return pal::pal_utf8string(context->invocation_name, value_buffer, value_buffer_size); + } + if (::strcmp(key, HOST_PROPERTY_BUNDLE_EXTRACTION_PATH) == 0) { if (!bundle::info_t::is_single_file_bundle()) @@ -167,6 +175,7 @@ int hostpolicy_context_t::initialize(const hostpolicy_init_t &hostpolicy_init, c application = args.managed_application; host_mode = hostpolicy_init.host_mode; host_path = hostpolicy_init.host_info.host_path; + invocation_name = args.invocation_name; breadcrumbs_enabled = enable_breadcrumbs; deps_json_t::rid_resolution_options_t rid_resolution_options diff --git a/src/native/corehost/hostpolicy/hostpolicy_context.h b/src/native/corehost/hostpolicy/hostpolicy_context.h index a7d8faf6f7a6f3..e815b59b038ae8 100644 --- a/src/native/corehost/hostpolicy/hostpolicy_context.h +++ b/src/native/corehost/hostpolicy/hostpolicy_context.h @@ -20,6 +20,7 @@ struct hostpolicy_context_t pal::string_t clr_path; host_mode_t host_mode; pal::string_t host_path; + pal::string_t invocation_name; bool breadcrumbs_enabled; mutable std::unordered_set breadcrumbs; From ba45ad5e04cd62a745dad6b6033786aaa29749d5 Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Fri, 31 Jul 2026 22:06:01 +0200 Subject: [PATCH 2/6] Clarify command-line argument construction --- src/coreclr/vm/corhost.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index fd0b665aad1101..809ecbccc4bf3c 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -218,12 +218,11 @@ HRESULT CorHost2::ExecuteApplication(LPCWSTR pwzAppFullName, } /* - * This method processes the arguments sent to the host which are then used - * to invoke the main method. - * Note - - * [0] - points to the native invocation name provided by the host. If the host - * does not provide one, it points to the assembly name that was sent by the host. - * The rest are the arguments sent to the assembly. + * This method constructs the array returned by Environment.GetCommandLineArgs(). + * The first element is passed separately from argv as exePath and uses the native + * invocation name when provided by the host. Otherwise, the assembly or bundle path + * is used. The remaining elements come from argv, which contains the arguments to the + * main method. */ static PTRARRAYREF SetCommandLineArgs(PCWSTR pwzAssemblyPath, int argc, PCWSTR* argv) { From 97ed3a15515485709f6f25038c067935fd52338e Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Fri, 31 Jul 2026 23:11:38 +0200 Subject: [PATCH 3/6] Preserve muxer command-line argument behavior --- docs/design/features/host-runtime-information.md | 2 +- src/coreclr/hosts/corerun/corerun.cpp | 3 +++ .../FrameworkDependentAppLaunch.cs | 12 ++++++++---- src/native/corehost/hostpolicy/args.cpp | 2 +- .../corehost/hostpolicy/hostpolicy_context.cpp | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/design/features/host-runtime-information.md b/docs/design/features/host-runtime-information.md index 8d25000ae46e3b..7add7052aef0a1 100644 --- a/docs/design/features/host-runtime-information.md +++ b/docs/design/features/host-runtime-information.md @@ -42,7 +42,7 @@ Directory containing the application. This is used for [`AppContext.BaseDirector `HOST_INVOCATION_NAME` -The name used to invoke the host, corresponding to the native process's `argv[0]`. This is used for the first element returned by [`Environment.GetCommandLineArgs()`](https://learn.microsoft.com/dotnet/api/system.environment.getcommandlineargs). +The name used to invoke an application host, corresponding to the native process's `argv[0]`. The apphost and `corerun` hosts provide this property for the first element returned by [`Environment.GetCommandLineArgs()`](https://learn.microsoft.com/dotnet/api/system.environment.getcommandlineargs). The `dotnet` muxer does not provide this property, preserving the managed application path as the first element. ### Deps files diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index 1de42c3bb9e42a..b4c2102b0a5eef 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -284,6 +284,9 @@ size_t HOST_CONTRACT_CALLTYPE get_runtime_property( if (::strcmp(key, HOST_PROPERTY_INVOCATION_NAME) == 0) { + if (config->invocation_name.empty()) + return -1; + pal::string_utf8_t value_utf8 = pal::convert_to_utf8(config->invocation_name.c_str()); size_t len = value_utf8.size() + 1; if (value_buffer_size < len) diff --git a/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs b/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs index f721ffc00916e2..b11fb72c6fc28f 100644 --- a/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs +++ b/src/installer/tests/HostActivation.Tests/FrameworkDependentAppLaunch.cs @@ -29,19 +29,23 @@ public void Muxer_Default() var dotnet = HostTestContext.BuiltDotNet; var appDll = sharedTestState.App.AppDll; - dotnet.Exec(appDll) + dotnet.Exec(appDll, "print_command_line_args") .CaptureStdErr() .CaptureStdOut() .Execute() .Should().Pass() - .And.HaveStdOutContaining("Hello World"); + .And.HaveStdOutContaining("Hello World") + .And.HaveStdOutContaining($"Environment.GetCommandLineArgs()[0] = {appDll}") + .And.HaveStdOutContaining("Environment.GetCommandLineArgs()[1] = print_command_line_args"); - dotnet.Exec("exec", appDll) + dotnet.Exec("exec", appDll, "print_command_line_args") .CaptureStdErr() .CaptureStdOut() .Execute() .Should().Pass() - .And.HaveStdOutContaining("Hello World"); + .And.HaveStdOutContaining("Hello World") + .And.HaveStdOutContaining($"Environment.GetCommandLineArgs()[0] = {appDll}") + .And.HaveStdOutContaining("Environment.GetCommandLineArgs()[1] = print_command_line_args"); } [Fact] diff --git a/src/native/corehost/hostpolicy/args.cpp b/src/native/corehost/hostpolicy/args.cpp index dab162ff86c981..d9fc1b5229696c 100644 --- a/src/native/corehost/hostpolicy/args.cpp +++ b/src/native/corehost/hostpolicy/args.cpp @@ -20,7 +20,7 @@ bool parse_arguments( const int argc, const pal::char_t* argv[], arguments_t& args) { - if (argc > 0) + if (init.host_mode == host_mode_t::apphost && argc > 0) args.invocation_name = argv[0]; pal::string_t managed_application_path; diff --git a/src/native/corehost/hostpolicy/hostpolicy_context.cpp b/src/native/corehost/hostpolicy/hostpolicy_context.cpp index 6498a49c952854..0408a640e554d2 100644 --- a/src/native/corehost/hostpolicy/hostpolicy_context.cpp +++ b/src/native/corehost/hostpolicy/hostpolicy_context.cpp @@ -124,7 +124,7 @@ namespace if (::strcmp(key, HOST_PROPERTY_INVOCATION_NAME) == 0) { - if (context->host_mode == host_mode_t::libhost) + if (context->invocation_name.empty()) return -1; return pal::pal_utf8string(context->invocation_name, value_buffer, value_buffer_size); From 52084795196375da5bb86ac296521c3da44d8852 Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Sat, 1 Aug 2026 08:26:07 +0200 Subject: [PATCH 4/6] Preserve corerun command-line argument behavior --- .../features/host-runtime-information.md | 2 +- src/coreclr/hosts/corerun/corerun.cpp | 20 ------------------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/docs/design/features/host-runtime-information.md b/docs/design/features/host-runtime-information.md index 7add7052aef0a1..8a33218c8ca2fd 100644 --- a/docs/design/features/host-runtime-information.md +++ b/docs/design/features/host-runtime-information.md @@ -42,7 +42,7 @@ Directory containing the application. This is used for [`AppContext.BaseDirector `HOST_INVOCATION_NAME` -The name used to invoke an application host, corresponding to the native process's `argv[0]`. The apphost and `corerun` hosts provide this property for the first element returned by [`Environment.GetCommandLineArgs()`](https://learn.microsoft.com/dotnet/api/system.environment.getcommandlineargs). The `dotnet` muxer does not provide this property, preserving the managed application path as the first element. +The name used to invoke an application host, corresponding to the native process's `argv[0]`. The apphost provides this property for the first element returned by [`Environment.GetCommandLineArgs()`](https://learn.microsoft.com/dotnet/api/system.environment.getcommandlineargs). Muxer-style hosts, including `dotnet` and `corerun`, do not provide this property, preserving the managed application path as the first element. ### Deps files diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index b4c2102b0a5eef..3ab04343b8a052 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -57,9 +57,6 @@ struct configuration // The full path to the Supplied managed entry assembly. string_t entry_assembly_fullpath; - // The name used to invoke corerun. - string_t invocation_name; - // Arguments to pass to managed entry assembly. int entry_assembly_argc; const char_t** entry_assembly_argv; @@ -282,21 +279,6 @@ size_t HOST_CONTRACT_CALLTYPE get_runtime_property( return len; } - if (::strcmp(key, HOST_PROPERTY_INVOCATION_NAME) == 0) - { - if (config->invocation_name.empty()) - return -1; - - pal::string_utf8_t value_utf8 = pal::convert_to_utf8(config->invocation_name.c_str()); - size_t len = value_utf8.size() + 1; - if (value_buffer_size < len) - return len; - - ::strncpy(value_buffer, value_utf8.c_str(), len - 1); - value_buffer[len - 1] = '\0'; - return len; - } - // Look up user-defined properties passed to corerun via -p/--property. assert(config->user_defined_keys.size() == config->user_defined_values.size()); pal::string_t key_native = pal::convert_from_utf8(key); @@ -754,8 +736,6 @@ static bool parse_args( return false; } - config.invocation_name = argv[0]; - for (int i = 1; i < argc; i++) { bool is_option = pal::is_cli_option(argv[i][0]); From eb6a989e3af1df8cc33c889cab08f1a1db3c0984 Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Sat, 1 Aug 2026 08:58:15 +0200 Subject: [PATCH 5/6] Assert apphost argument invariant --- src/native/corehost/hostpolicy/args.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/native/corehost/hostpolicy/args.cpp b/src/native/corehost/hostpolicy/args.cpp index d9fc1b5229696c..7582542ec49d05 100644 --- a/src/native/corehost/hostpolicy/args.cpp +++ b/src/native/corehost/hostpolicy/args.cpp @@ -20,12 +20,12 @@ bool parse_arguments( const int argc, const pal::char_t* argv[], arguments_t& args) { - if (init.host_mode == host_mode_t::apphost && argc > 0) - args.invocation_name = argv[0]; - pal::string_t managed_application_path; if (init.host_mode == host_mode_t::apphost) { + assert(argc > 0 && argv != nullptr); + args.invocation_name = argv[0]; + // Find the managed app in the same directory managed_application_path = init.host_info.app_path; From 9af68ce233b20c569135700a3f83fa805c8f923b Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Sat, 1 Aug 2026 13:32:02 +0200 Subject: [PATCH 6/6] Rename invocation property to ARGV0 --- docs/design/features/host-runtime-information.md | 2 +- src/coreclr/vm/corhost.cpp | 2 +- src/native/corehost/host_runtime_contract.h | 2 +- src/native/corehost/hostpolicy/hostpolicy_context.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/design/features/host-runtime-information.md b/docs/design/features/host-runtime-information.md index 8a33218c8ca2fd..5501d8c0469813 100644 --- a/docs/design/features/host-runtime-information.md +++ b/docs/design/features/host-runtime-information.md @@ -40,7 +40,7 @@ Directory containing the application. This is used for [`AppContext.BaseDirector [Runtime identifier](https://learn.microsoft.com/dotnet/core/rid-catalog) for the application. This is used for [`RuntimeInformation.RuntimeIdentifier`](https://learn.microsoft.com/dotnet/api/system.runtime.interopservices.runtimeinformation.runtimeidentifier). -`HOST_INVOCATION_NAME` +`ARGV0` The name used to invoke an application host, corresponding to the native process's `argv[0]`. The apphost provides this property for the first element returned by [`Environment.GetCommandLineArgs()`](https://learn.microsoft.com/dotnet/api/system.environment.getcommandlineargs). Muxer-style hosts, including `dotnet` and `corerun`, do not provide this property, preserving the managed application path as the first element. diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index 809ecbccc4bf3c..3dfab73f92b239 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -238,7 +238,7 @@ static PTRARRAYREF SetCommandLineArgs(PCWSTR pwzAssemblyPath, int argc, PCWSTR* SaveManagedCommandLine(pwzAssemblyPath, argc, argv); StackSString invocationName; - PCWSTR exePath = HostInformation::GetProperty(HOST_PROPERTY_INVOCATION_NAME, invocationName) + PCWSTR exePath = HostInformation::GetProperty(HOST_PROPERTY_ARGV0, invocationName) ? invocationName.GetUnicode() : (Bundle::AppIsBundle() ? static_cast(Bundle::AppBundle->Path()) : pwzAssemblyPath); diff --git a/src/native/corehost/host_runtime_contract.h b/src/native/corehost/host_runtime_contract.h index 7d149fe8b774c0..8bba040a6d5a03 100644 --- a/src/native/corehost/host_runtime_contract.h +++ b/src/native/corehost/host_runtime_contract.h @@ -19,7 +19,7 @@ #define HOST_PROPERTY_BUNDLE_PROBE "BUNDLE_PROBE" #define HOST_PROPERTY_BUNDLE_EXTRACTION_PATH "BUNDLE_EXTRACTION_PATH" #define HOST_PROPERTY_ENTRY_ASSEMBLY_NAME "ENTRY_ASSEMBLY_NAME" -#define HOST_PROPERTY_INVOCATION_NAME "HOST_INVOCATION_NAME" +#define HOST_PROPERTY_ARGV0 "ARGV0" #define HOST_PROPERTY_NATIVE_DLL_SEARCH_DIRECTORIES "NATIVE_DLL_SEARCH_DIRECTORIES" #define HOST_PROPERTY_PINVOKE_OVERRIDE "PINVOKE_OVERRIDE" #define HOST_PROPERTY_PLATFORM_RESOURCE_ROOTS "PLATFORM_RESOURCE_ROOTS" diff --git a/src/native/corehost/hostpolicy/hostpolicy_context.cpp b/src/native/corehost/hostpolicy/hostpolicy_context.cpp index 0408a640e554d2..3bf16e9bf9c322 100644 --- a/src/native/corehost/hostpolicy/hostpolicy_context.cpp +++ b/src/native/corehost/hostpolicy/hostpolicy_context.cpp @@ -122,7 +122,7 @@ namespace return pal::pal_utf8string(get_filename_without_ext(context->application), value_buffer, value_buffer_size); } - if (::strcmp(key, HOST_PROPERTY_INVOCATION_NAME) == 0) + if (::strcmp(key, HOST_PROPERTY_ARGV0) == 0) { if (context->invocation_name.empty()) return -1;