Does OpenFileDialog.ShowDialog () throw an exception?

I am trying to show a dialog with one of my WPF view model commands, however when I call ShowDialog() it throws a System.ArgumentException , I was wondering if anyone could give me a hint about why?

Here is my code:

 Public ReadOnly Property OpenParser As ICommand Get Return New RelayCommand(Sub(param As Object) OpenParserExecute(DirectCast(param, Frame))) End Get End Property Public Sub OpenParserExecute(ByVal mFrame As Frame) SaveParserExecute() Dim mOpenDialog As OpenFileDialog = OpenDialog If mOpenDialog.ShowDialog() Then ' Lines the throws the exception CurrentParser = New ParserEditorModel(mOpenDialog.FileName) mFrame.Navigate(New ParserEditor(CurrentParser)) End If End Sub 

StackTrace on request:

 at MS.Internal.Interop.HRESULT.ThrowIfFailed(String message) at MS.Internal.AppModel.ShellUtil.GetShellItemForPath(String path) at Microsoft.Win32.FileDialog.PrepareVistaDialog(IFileDialog dialog) at Microsoft.Win32.FileDialog.RunVistaDialog(IntPtr hwndOwner) at Microsoft.Win32.FileDialog.RunDialog(IntPtr hwndOwner) at Microsoft.Win32.CommonDialog.ShowDialog() at WinTransform.GUI.MainWindowModel.OpenParserExecute(Frame mFrame) in C:\Users\Alex\Desktop\MEDLI\branches\WinTransform\GUI\ViewModels\MainWindowModel.vb:line 38 
0
source share
1 answer

Since ShowDialog() itself returns Nullable(Of Boolean) , and the If statement expects a non-Nullable Boolean .

You will need to return the return value to the Boolean dialog box, and if True returns the selected file through your Filename dialog property.

An example .

+3
source

Source: https://habr.com/ru/post/1403501/


All Articles