From 385076daa4dabce5950139d95096a8e371d144bf Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Thu, 21 Nov 2019 17:13:44 -0600 Subject: [PATCH] (GH-1949) Release mode - account for null entry assembly Some testing platforms will not provide an entry assembly, so it can come back null. In this case, look for the entry assembly first, then look at the executing assembly. This should work in near all test cases. This is also not part of official release code. --- src/chocolatey/infrastructure.app/ApplicationParameters.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index 072d4c6ec1..cf0f2e882c 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -45,8 +45,10 @@ public static class ApplicationParameters // we might be testing on a server or in the local debugger. Either way, // start from the assembly location and if unfound, head to the machine // locations instead. This is a merge of official and Debug modes. - public static readonly string InstallLocation = _fileSystem.file_exists(_fileSystem.combine_paths(_fileSystem.get_directory_name(Assembly.GetEntryAssembly().CodeBase.Replace("file:///", string.Empty)), "chocolatey.dll")) ? - _fileSystem.get_directory_name(Assembly.GetEntryAssembly().CodeBase.Replace("file:///", string.Empty)) : + private static IAssembly _assemblyForLocation = Assembly.GetEntryAssembly().UnderlyingType != null ? Assembly.GetEntryAssembly() : Assembly.GetExecutingAssembly(); + public static readonly string InstallLocation = _fileSystem.file_exists(_fileSystem.combine_paths(_fileSystem.get_directory_name(_assemblyForLocation.CodeBase.Replace("file:///", string.Empty)), "chocolatey.dll")) || + _fileSystem.file_exists(_fileSystem.combine_paths(_fileSystem.get_directory_name(_assemblyForLocation.CodeBase.Replace("file:///", string.Empty)), "choco.exe")) ? + _fileSystem.get_directory_name(_assemblyForLocation.CodeBase.Replace("file:///", string.Empty)) : !string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName)) ? System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) : @"C:\ProgramData\Chocolatey"