dotnet/wpf · error · ArgumentException

SR.InvalidTempFileName

Error message

SR.InvalidTempFileName

What it means

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.

Solutions

  1. Supply a valid non-empty temp file path, e.g. Path.GetTempFileName()
  2. Validate the string before constructing (arg check)
  3. Fix the configuration/source that yields the empty path

Example fix

// before
new ByteRangeDownloader(uri, handle, tempFileName /* "" */);
// after
if (string.IsNullOrEmpty(tempFileName)) throw new ArgumentException("tempFileName required");
new ByteRangeDownloader(uri, handle, tempFileName);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(tempFileName))
    throw new ArgumentException("A non-empty temp file name is required", nameof(tempFileName));
if (!File.Exists(tempFileName))
    tempFileName = Path.GetTempFileName();

Prevention

When it happens

Trigger: Constructing ByteRangeDownloader with tempFileName = "" or string.Empty.

Common situations: Config or download pipeline passing an unset/empty temp file path variable, or a path derived from an empty environment setting.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/b19c69a4d064ddbe. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/ByteRangeDownloader.cs:57

        //
        //------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Constructor for ByteRangeDownloader - for UrlMon usage
        /// </summary>
        /// <param name="eventHandle">event to signal when new data is available in tempStream</param>
        /// <param name="requestedUri">uri we should make requests to</param>
        /// <param name="tempFileName">temp file to write to</param>
        internal ByteRangeDownloader(Uri requestedUri, string tempFileName, SafeWaitHandle eventHandle)
            : this(requestedUri, eventHandle)
        {
            ArgumentNullException.ThrowIfNull(tempFileName);

            if (tempFileName.Length <= 0)
            {
                throw new ArgumentException(SR.InvalidTempFileName, nameof(tempFileName));
            }

            _tempFileStream = File.Open(tempFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
        }

        /// <summary>
        /// Constructor for ByteRangeDownloader - used by NetStream who owns the tempStream
        /// </summary>
        /// <param name="eventHandle">event to signal when new data is available in tempStream</param>
        /// <param name="fileMutex">mutex to synchronize access to tempStream</param>
        /// <param name="requestedUri">uri we should make requests to</param>
        /// <param name="tempStream">stream to write data to</param>
        internal ByteRangeDownloader(Uri requestedUri, Stream tempStream, SafeWaitHandle eventHandle, Mutex fileMutex)
            : this(requestedUri, eventHandle)
        {
            Debug.Assert(fileMutex != null, "FileMutex must be a valid mutex");
            Debug.Assert(tempStream != null, "ByteRangeDownloader requires a stream to write to");
            _tempFileStream = tempStream;

View on GitHub (pinned to 81131a70a4)