dotnet/wpf · error · ArgumentException

SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriContent"…

Error message

SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriContent", "OriginalString")

What it means

Application.GetContentStream(Uri) throws ArgumentException (SR.ArgumentPropertyMustNotBeNull naming uriContent.OriginalString) when the passed Uri's OriginalString is null. Content files are loose files deployed alongside the application, and the API requires a valid relative or pack-application Uri to locate the content part.

Solutions

  1. Build the Uri from a validated non-null string, e.g. new Uri(@"Content\help.htm", UriKind.Relative)
  2. Guard before calling: if (uri?.OriginalString == null) handle/throw
  3. Fix the configuration or producer yielding the null-string Uri

Example fix

// before
Uri uri = GetContentPath(); // OriginalString == null
var sri = Application.GetContentStream(uri);

// after
var uri = new Uri("Content/help.htm", UriKind.Relative);
var sri = Application.GetContentStream(uri);
Defensive patterns

Strategy: validation

Validate before calling

if (uri == null || uri.OriginalString == null)
    return null; // or throw a clearer error
var sri = Application.GetContentStream(uri);

Type guard

static bool IsValidContentUri(Uri u) => u?.OriginalString != null;

Try / catch

try { sri = Application.GetContentStream(uri); }
catch (ArgumentException ex) { Log(ex); sri = null; }

Prevention

When it happens

Trigger: Calling GetContentStream with a Uri whose OriginalString is null, typically produced by uninitialized config values or deserialization.

Common situations: Content path settings missing at runtime; a bound Uri property never initialized before content loading runs.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs:611

        ///
        /// If the Uri doesn't map to any content file, this method returns null.
        ///
        /// The accepted uri could be relative uri or pack://Application:,,,/ uri.
        ///
        ///   Such as
        ///         "image/picture1.jpg"
        ///    or
        ///        "pack://application:,,,/image/picture1.jpg"
        ///
        /// </summary>
        /// <param name="uriContent">the uri maps to the Content File</param>
        /// <returns>PackagePart or null</returns>
        public static StreamResourceInfo GetContentStream(Uri uriContent)
        {
            ArgumentNullException.ThrowIfNull(uriContent);

            if (uriContent.OriginalString == null)
                throw new ArgumentException(SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriContent", "OriginalString"));

            if (uriContent.IsAbsoluteUri && !BaseUriHelper.IsPackApplicationUri(uriContent))
            {
                throw new ArgumentException(SR.NonPackAppAbsoluteUriNotAllowed);
            }

            ContentFilePart part = GetResourceOrContentPart(uriContent) as ContentFilePart;
            return (part == null) ? null : new StreamResourceInfo(part.GetSeekableStream(), part.ContentType);
        }

        /// <summary>
        /// Get PackagePart for a uri, the uri maps to a file which comes from the place
        /// where the application was originally deployed.
        ///
        /// The accepted uri could be relative uri such as "foo.jpg"
        ///
        /// or  pack Uri, "pack://siteoforigin:,,,/foo.jpg"
        ///

View on GitHub (pinned to 81131a70a4)