Skip to content

Commit

Permalink
(GH-1949) Release mode - account for null entry assembly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferventcoder committed Nov 21, 2019
1 parent ef3c6d7 commit 385076d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 385076d

Please sign in to comment.