Skip to content

Commit 385076d

Browse files
committed
(chocolateyGH-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.
1 parent ef3c6d7 commit 385076d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/chocolatey/infrastructure.app/ApplicationParameters.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public static class ApplicationParameters
4545
// we might be testing on a server or in the local debugger. Either way,
4646
// start from the assembly location and if unfound, head to the machine
4747
// locations instead. This is a merge of official and Debug modes.
48-
public static readonly string InstallLocation = _fileSystem.file_exists(_fileSystem.combine_paths(_fileSystem.get_directory_name(Assembly.GetEntryAssembly().CodeBase.Replace("file:///", string.Empty)), "chocolatey.dll")) ?
49-
_fileSystem.get_directory_name(Assembly.GetEntryAssembly().CodeBase.Replace("file:///", string.Empty)) :
48+
private static IAssembly _assemblyForLocation = Assembly.GetEntryAssembly().UnderlyingType != null ? Assembly.GetEntryAssembly() : Assembly.GetExecutingAssembly();
49+
public static readonly string InstallLocation = _fileSystem.file_exists(_fileSystem.combine_paths(_fileSystem.get_directory_name(_assemblyForLocation.CodeBase.Replace("file:///", string.Empty)), "chocolatey.dll")) ||
50+
_fileSystem.file_exists(_fileSystem.combine_paths(_fileSystem.get_directory_name(_assemblyForLocation.CodeBase.Replace("file:///", string.Empty)), "choco.exe")) ?
51+
_fileSystem.get_directory_name(_assemblyForLocation.CodeBase.Replace("file:///", string.Empty)) :
5052
!string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName)) ?
5153
System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) :
5254
@"C:\ProgramData\Chocolatey"

0 commit comments

Comments
 (0)