{"record":{"id":"b19c69a4d064ddbe","repo":"dotnet/wpf","slug":"sr-invalidtempfilename","errorCode":null,"errorMessage":"SR.InvalidTempFileName","messagePattern":"SR\\.InvalidTempFileName","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs","lineNumber":57,"sourceCode":"        //\n        //------------------------------------------------------\n\n        #region Constructors\n\n        /// <summary>\n        /// Constructor for ByteRangeDownloader - for UrlMon usage\n        /// </summary>\n        /// <param name=\"eventHandle\">event to signal when new data is available in tempStream</param>\n        /// <param name=\"requestedUri\">uri we should make requests to</param>\n        /// <param name=\"tempFileName\">temp file to write to</param>\n        internal ByteRangeDownloader(Uri requestedUri, string tempFileName, SafeWaitHandle eventHandle)\n            : this(requestedUri, eventHandle)\n        {\n            ArgumentNullException.ThrowIfNull(tempFileName);\n\n            if (tempFileName.Length <= 0)\n            {\n                throw new ArgumentException(SR.InvalidTempFileName, nameof(tempFileName));\n            }\n\n            _tempFileStream = File.Open(tempFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);\n        }\n\n        /// <summary>\n        /// Constructor for ByteRangeDownloader - used by NetStream who owns the tempStream\n        /// </summary>\n        /// <param name=\"eventHandle\">event to signal when new data is available in tempStream</param>\n        /// <param name=\"fileMutex\">mutex to synchronize access to tempStream</param>\n        /// <param name=\"requestedUri\">uri we should make requests to</param>\n        /// <param name=\"tempStream\">stream to write data to</param>\n        internal ByteRangeDownloader(Uri requestedUri, Stream tempStream, SafeWaitHandle eventHandle, Mutex fileMutex)\n            : this(requestedUri, eventHandle)\n        {\n            Debug.Assert(fileMutex != null, \"FileMutex must be a valid mutex\");\n            Debug.Assert(tempStream != null, \"ByteRangeDownloader requires a stream to write to\");\n            _tempFileStream = tempStream;","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs#L39-L75","documentation":"The ByteRangeDownloader constructor validates tempFileName before opening it; an empty string is rejected with ArgumentException(SR.InvalidTempFileName). The name must be a non-empty, existing path opened with ReadWrite access.","triggerScenarios":"Constructing ByteRangeDownloader with tempFileName = \"\" or string.Empty.","commonSituations":"Config or download pipeline passing an unset/empty temp file path variable, or a path derived from an empty environment setting.","solutions":["Supply a valid non-empty temp file path, e.g. Path.GetTempFileName()","Validate the string before constructing (arg check)","Fix the configuration/source that yields the empty path"],"exampleFix":"// before\nnew ByteRangeDownloader(uri, handle, tempFileName /* \"\" */);\n// after\nif (string.IsNullOrEmpty(tempFileName)) throw new ArgumentException(\"tempFileName required\");\nnew ByteRangeDownloader(uri, handle, tempFileName);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(tempFileName))\n    throw new ArgumentException(\"A non-empty temp file name is required\", nameof(tempFileName));\nif (!File.Exists(tempFileName))\n    tempFileName = Path.GetTempFileName();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate temp paths before constructing downloader","Use Path.GetTempFileName() to guarantee a valid path","Log the source of path config values to catch empty settings early"],"tags":["wpf","packaging","argument-validation"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}