Skip to content

Can't start LogExpert if font in settings file is not found #468

@AndisGrossteins

Description

@AndisGrossteins

After restoring settings.json file from a backup on a new installation, I get following error in a MessageBox upon start:

Cannot open connection to first instance (Font 'Hack NF' cannot be found.)
Closing the message exits program.

I get that the "Cannot open connection to first instance" comes from implementation of the "Allow only one instance" option but missing font or in this case changed font name should not cause an exception or block startup.

This is LogExpert version 1.20 but same issue is present after building from the Development branch.

The line from the NLog log file and the actual exception hidden behind the MessageBox:

Mutex error, giving up: Font 'Hack NF' cannot be found. System.ArgumentException System.ArgumentException: Font 'TestMissingFont' cannot be found.
   at System.Drawing.FontFamily.CreateFontFamily(String name, FontCollection fontCollection)
   at System.Drawing.FontFamily..ctor(String name)
   at LogExpert.Dialogs.BookmarkWindow.SetFont(String fontName, Single fontSize) in C:\Development\LogExpert\src\LogExpert.UI\Dialogs\BookmarkWindow.cs:line 229
   at LogExpert.Dialogs.BookmarkWindow.PreferencesChanged(String fontName, Single fontSize, Boolean setLastColumnWidth, Int32 lastColumnWidth, SettingsFlags flags) in C:\Development\LogExpert\src\LogExpert.UI\Dialogs\BookmarkWindow.cs:line 157
   at LogExpert.UI.Controls.LogTabWindow.LogTabWindow.InitBookmarkWindow() in C:\Development\LogExpert\src\LogExpert.UI\Dialogs\LogTabWindow\LogTabWindow.cs:line 684
   at LogExpert.UI.Controls.LogTabWindow.LogTabWindow.InitToolWindows() in C:\Development\LogExpert\src\LogExpert.UI\Dialogs\LogTabWindow\LogTabWindow.cs:line 661
   at LogExpert.UI.Controls.LogTabWindow.LogTabWindow..ctor(String[] fileNames, Int32 instanceNumber, Boolean showInstanceNumbers, IConfigManager configManager) in C:\Development\LogExpert\src\LogExpert.UI\Dialogs\LogTabWindow\LogTabWindow.cs:line 177
   at LogExpert.UI.Extensions.LogWindow.AbstractLogTabWindow.Create(String[] fileNames, Int32 instanceNumber, Boolean showInstanceNumbers, IConfigManager configManager) in C:\Development\LogExpert\src\LogExpert.UI\Extensions\LogWindow\AbstractLogTabWindow.cs:line 15
   at LogExpert.Program.Main(String[] args) in C:\Development\LogExpert\src\LogExpert\Program.cs:line 91

That could be solved by catching a more specific exception in the try..catch statement. Also applies to other places in the codebase where this is prevalent.

Another similar issue with settings JSON deserialization where settings are silently reset to defaults. That leads to loss of settings file contents and subsequent user frustration. As far as I can tell, columnizer references can't be instantiated properly. In some places the [JsonIgnore] property attribute (as in FilterParams.CurrentColumnizer in FilterParams.cs) is actually from System.Text.Json.Serialization but settings serialization is done with Newtonsoft.Json so the attribute is ignored.

I think I've solved the latter issue and could make a PR. Just need to do some manual tests but it's already 1am here.

Metadata

Metadata

Assignees

Labels

bugPesky little gritter, needs squashing

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions