{"record":{"id":"9bb15029621ceb33","repo":"duplicati/duplicati","slug":"failed-to-retrieve-alternate-data-stream-size","errorCode":null,"errorMessage":"Failed to retrieve alternate data stream size.","messagePattern":"Failed to retrieve alternate data stream size\\.","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"Duplicati/Library/Common/IO/SystemIOWindows.cs","lineNumber":719,"sourceCode":"        {\n            if (!IsAlternateDataStream(path))\n                return new FileInfo(AddExtendedDevicePathPrefix(path)).Length;\n\n            using SafeFileHandle handle = Win32API.CreateFileW(\n                        AddExtendedDevicePathPrefix(path),\n                        Win32API.FILE_READ_ATTRIBUTES,\n                        Win32API.FILE_SHARE_READ | Win32API.FILE_SHARE_WRITE | Win32API.FILE_SHARE_DELETE, // Broad sharing flags avoid collisions\n                        IntPtr.Zero,\n                        Win32API.OPEN_EXISTING,\n                        0,\n                        IntPtr.Zero);\n\n            if (handle.IsInvalid)\n                throw new Win32Exception(Marshal.GetLastWin32Error(), \"Failed to open handle to alternative data stream \");\n\n            // Retrieve the size directly from the stream handle\n            if (!Win32API.GetFileSizeEx(handle, out long streamSize))\n                throw new Win32Exception(Marshal.GetLastWin32Error(), \"Failed to retrieve alternate data stream size.\");\n\n            return streamSize;\n        }\n\n        public void CreateSymlink(string symlinkfile, string target, bool asDir)\n        {\n            if (FileExists(symlinkfile) || DirectoryExists(symlinkfile))\n                throw new IOException(string.Format(\"File already exists: {0}\", symlinkfile));\n\n\n            if (asDir)\n            {\n                Directory.CreateSymbolicLink(AddExtendedDevicePathPrefix(symlinkfile), target);\n            }\n            else\n            {\n                File.CreateSymbolicLink(AddExtendedDevicePathPrefix(symlinkfile), target);\n            }","sourceCodeStart":701,"sourceCodeEnd":737,"githubUrl":"https://github.com/duplicati/duplicati/blob/3f348be3e33f5d72d414e3ad55839c2ba34dda67/Duplicati/Library/Common/IO/SystemIOWindows.cs#L701-L737","documentation":"Thrown by SystemIOWindows.FileLength after a valid handle to an alternate data stream was opened but Win32API.GetFileSizeEx returned false. This is rarer than [420]: the stream was found and opened, yet the kernel could not report its size. The native error code in the Win32Exception explains why.","triggerScenarios":"CreateFileW succeeded but GetFileSizeEx failed on the resulting handle, which can happen when the handle is to a device-backed reparse point, a remote stream whose size is not reported by the redirector, or the stream was truncated mid-call.","commonSituations":"ADS on files hosted on SMB/Samba shares with protocol limitations; ADS on files backed by special devices; transient I/O during concurrent writers.","solutions":["Inspect Win32Exception.NativeErrorCode to determine the kernel-level cause.","Retry once for transient network errors (e.g. ERROR_NETNAME_DELETED).","Fall back to reading the stream to compute length if size cannot be queried.","Skip the stream and log a warning if it is a non-critical metadata stream."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { len = systemIO.FileLength(adsPath); }\ncatch (System.ComponentModel.Win32Exception ex)\n{\n    logger.LogError(ex, \"GetFileSizeEx failed for {Path} (code {Code})\", adsPath, ex.NativeErrorCode);\n    // fall back to reading the stream to compute length, or skip\n}","preventionTips":["For network-hosted ADS, prefer local staging so size queries are reliable.","Log NativeErrorCode to distinguish transient network faults from permanent failures.","Fall back to streaming the stream content to compute size when the kernel cannot report it."],"tags":["windows","io","alternate-data-stream","win32"],"backgroundTag":null,"analyzedSha":"3f348be3e33f5d72d414e3ad55839c2ba34dda67","analyzedAt":"2026-08-13T16:48:27.008Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}