One of my clients is experiencing a crash in my WPF application while saving the file.
My save file code:
var saveFileDialog = new SaveFileDialog { InitialDirectory = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"\MyApp"), FileName = "MyFile", OverwritePrompt = true, AddExtension = true }; if (saveFileDialog.ShowDialog() == true) { ... }
And here is the exception they get:
Value does not fall within the expected range. A System.ArgumentException occurred 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()
(Where the ShowDialog in the last line refers to the call that I make in my code above.)
So my hunch is that in my client case, calling Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments) returns what SaveFileDialog doesn't like as InitialDirectory . I found in a web search (and confirmed) that this error occurs when passing a relative path as InitialDirectory to SaveFileDialog. Is it possible that Environment.SpecialFolder.MyDocuments can be returned as a relative path? If not, does anyone know of another potentially invalid format? Could there be a reason for the specific network path SpecialFolder.MyDocuments? Any other ideas?
I do not have direct access to my car for customers, and they are not particularly effective in technology, so it is impossible to be 100% sure what is happening.
source share