Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug fix] The bin path is null caused the program startup failure #396

Closed
wants to merge 1 commit into from

Conversation

BlueHtml
Copy link

Version 1.0.9 uses Assembly.GetExecutingAssembly().Location to get the directory where Garnet is located, but it return an empty string in SingleFile mode (source link), leading to program startup failure with the error: Unable to initialize server due to exception: Value cannot be null. (Parameter 'path1'). Using AppContext.BaseDirectory works well.

Assembly.Location Property: In .NET 5 and later versions, for bundled assemblies, the value returned is an empty string. (source link)

The test code is as follows:

var binPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Console.WriteLine($"AppContext.BaseDirectory:{AppContext.BaseDirectory}, is null:{AppContext.BaseDirectory is null}");
Console.WriteLine($"Assembly.GetExecutingAssembly().Location:{Assembly.GetExecutingAssembly().Location}, is null:{Assembly.GetExecutingAssembly().Location is null}");
Console.WriteLine($"binPath:{binPath}, is null:{binPath is null}");

The output is as follows:

PS D:\tmp\test\bb> \code\tmp\garnet\main\GarnetServer\bin\Release\net8.0\publish\linux-arm64\GarnetServer.exe
    _________
   /_||___||_\      Garnet 1.0.9 64 bit; standalone mode
   '. \   / .'      Port: 3278
     '.\ /.'        https://aka.ms/GetGarnet
       '.'

AppContext.BaseDirectory:D:\code\tmp\garnet\main\GarnetServer\bin\Release\net8.0\publish\linux-arm64\, is null:False
Assembly.GetExecutingAssembly().Location:, is null:False
binPath:, is null:True
Unable to initialize server due to exception: Value cannot be null. (Parameter 'path1')
PS D:\tmp\test\bb>

@jiripospisil
Copy link

I can confirm that this fixes the start-up failure. Not related to this PR directly, but what I don't understand is why it's even attempting to load the file like this in the first place when the path to the JSON file could be specified in the config file (or better yet, specify a directory in the config file and all JSON files from there could be automatically loaded). Thoughts?

@badrishc
Copy link
Contributor

However we handle path here should be analogous to the way we default paths when LogDir or ChechpointDir is null.

@badrishc
Copy link
Contributor

badrishc commented May 17, 2024

Temporary fix is in this PR: #397 and after merge we will release 1.0.10
We will improve the custom commands info handling next week.

@badrishc badrishc closed this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants