{"record":{"id":"dd4fe3b7306729a9","repo":"beeradmoore/dlss-swapper","slug":"failed-to-get-result-from-file-open-dialog","errorCode":null,"errorMessage":"Failed to get result from file open dialog.","messagePattern":"Failed to get result from file open dialog\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Helpers/FileSystemHelper.cs","lineNumber":187,"sourceCode":"\n            fileOpenDialog.Show(new HWND(hWnd));\n\n            var results = new List<string>();\n\n            if (pickMultiple)\n            {\n                fileOpenDialog.GetResults(out var ppsiArray);\n\n                unsafe\n                {\n                    ppsiArray.GetCount(out uint count);\n                    for (uint i = 0; i < count; ++i)\n                    {\n                        ppsiArray.GetItemAt(i, out var ppsi);\n\n                        if (ppsi is null)\n                        {\n                            throw new Exception(\"Failed to get result from file open dialog.\");\n                        }\n\n                        PWSTR filename;\n                        ppsi.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, &filename);\n                        var pathName = filename.ToString();\n                        results.Add(pathName);\n                    }\n                }\n            }\n            else\n            {\n                fileOpenDialog.GetResult(out var ppsi);\n\n                if (ppsi is null)\n                {\n                    throw new Exception(\"Failed to get result from file open dialog.\");\n                }\n","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/beeradmoore/dlss-swapper/blob/ab9b1e2d4bb04187c48fe58eeea06c2b0ea71fbb/src/Helpers/FileSystemHelper.cs#L169-L205","documentation":"In FileSystemHelper.OpenFileInternal (multi-select path), each item of the ShellItemArray returned by the IFileOpenDialog is fetched with GetItemAt. If any item comes back null the helper cannot produce a path for it and throws this exception. It indicates the Shell gave a result collection containing an unusable entry.","triggerScenarios":"During enumeration of a multi-file selection, ppsiArray.GetItemAt(i, out ppsi) succeeds but yields a null IShellItem at index i — e.g. an item that was removed or became unavailable between selection and retrieval (network share/removed device), or a shell namespace item without a filesystem representation.","commonSituations":"User selects files on a network drive or removable media that disconnects before the dialog result is processed; virtual shell items (This PC, libraries) surfaced into the result; Windows shell edge cases with unusual file pickers.","solutions":["Treat null items as skippable: continue enumerating remaining items instead of failing the whole operation.","GetDisplayName on each item inside try/catch and skip items whose SIGDN_FILESYSPATH cannot be resolved.","Validate the selection before closing (filter to filesystem items) if the dialog configuration allows it.","Log the index and count when skipping to aid diagnosing shell-provided bad items."],"exampleFix":"// before\nppsiArray.GetItemAt(i, out var ppsi);\nif (ppsi is null) throw new Exception(\"Failed to get result from file open dialog.\");\n// after\nppsiArray.GetItemAt(i, out var ppsi);\nif (ppsi is null) continue; // skip unavailable item instead of failing all selected files","handlingStrategy":"type-guard","validationCode":"// no pre-call validation possible for shell internals; guard the item after GetItemAt\nppsiArray.GetItemAt(i, out var ppsi);\nif (ppsi is null) { skipped++; continue; }","typeGuard":"static bool IsUsableShellItem(IShellItem? item) => item is not null;","tryCatchPattern":"try\n{\n    CollectDialogItems(ppsiArray, count, results);\n}\ncatch (Exception ex) when (ex.Message == \"Failed to get result from file open dialog.\")\n{\n    // return whatever paths were collected so far instead of failing all\n}","preventionTips":["Skip null items and log them rather than aborting a multi-select result.","Check network/removable paths for availability before relying on them.","Resolve SIGDN_FILESYSPATH defensively; some shell items have no filesystem path."],"tags":["file-dialog","windows-shell","filesystem"],"backgroundTag":"null-argument","analyzedSha":"ab9b1e2d4bb04187c48fe58eeea06c2b0ea71fbb","analyzedAt":"2026-09-15T05:25:32.979Z","contentChangedAt":"2026-09-15T05:25:32.979Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}