AvaloniaUI/Avalonia

Unhandled exception in MsBoxStandardView constructor

David-A-Blankenship opened this issue · 3 comments

Describe the bug

When creating a message box through MsBox.Avalonia.MessageBoxManager.GetMessageBoxStandard I get an exception that is originating in the Markdown.Avalonia.Markdown constructor. This exception is not caught and handled in either, resulting in it being passed back to my application. Here is the stack trace for this exception:

System.IO.FileNotFoundException: Unable to find the specified file.
at Interop.Sys.GetCwdHelper(Byte* ptr, Int32 bufferSize)
at Interop.Sys.GetCwd()
at Markdown.Avalonia.Markdown..ctor()
at Markdown.Avalonia.MarkdownScrollViewer..ctor()
at MsBox.Avalonia.Controls.MsBoxStandardView.!XamlIlPopulate(IServiceProvider, MsBoxStandardView)
at MsBox.Avalonia.Controls.MsBoxStandardView.!XamlIlPopulateTrampoline(MsBoxStandardView)
at MsBox.Avalonia.Controls.MsBoxStandardView.InitializeComponent(Boolean loadXaml)
at MsBox.Avalonia.Controls.MsBoxStandardView..ctor()
at MsBox.Avalonia.MessageBoxManager.GetMessageBoxStandard(MessageBoxStandardParams params)
at HanumanInstitute.MvvmDialogs.Avalonia.MessageBox.MessageBoxApi.ShowMessageBoxAsync(Window owner, MessageBoxApiSettings settings, MessageBoxMode mode)

It looks like this exception is originating the the Markdown constructor in a call to Environment.CurrentDirectory.

To Reproduce

Avalonia 11.2.1
.NET 8.0.7
Rocky Linux 8.9 64-bit

Unfortunately, I do not have good steps to reproduce this issue. One of my users is having this problem. I am not sure why the Environment.CurrentDirectory call is throwing this exception.

Expected behavior

I would expect that this exception is caught and handled in the Markdown object, but it could also be caught and handled in the message box object and have the message box displayed without the Markdown control.

Avalonia version

11.2.1

OS

Linux

Additional context

I have also opened an issue in the Markdown.Avalonia project.
whistyun/Markdown.Avalonia#166

Neither MsBoxStandardView nor Markdown.Avalonia are maintained by Avalonia team. This bug doesn't seem to be relevant to this repository, and I can't help with this error.

It seems to be caused in runtime method: https://github.com/dotnet/runtime/blob/2c9aaafe07d273a565f577e443fdb0e02543d7d5/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetCwd.cs#L49
But I don't see opened issue there on topic https://github.com/dotnet/runtime/issues?q=is%3Aissue%20state%3Aopen%20GetCwd.

Either way, my recommendation to Markdown.Avalonia might be to try using AppContext.BaseDirectory instead. Or at least as a fallback.

Thank you. I failed to notice that is was in MessageBox.Avalonia. I have submitted an issue there.