{"record":{"id":"90fb95e5e8ba7326","repo":"dotnet/wpf","slug":"sr-format-sr-argumentpropertymustnotbenull-uricontent","errorCode":null,"errorMessage":"SR.Format(SR.ArgumentPropertyMustNotBeNull, \"uriContent\", \"OriginalString\")","messagePattern":"SR\\.Format\\(SR\\.ArgumentPropertyMustNotBeNull, \"uriContent\", \"OriginalString\"\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs","lineNumber":611,"sourceCode":"        ///\n        /// If the Uri doesn't map to any content file, this method returns null.\n        ///\n        /// The accepted uri could be relative uri or pack://Application:,,,/ uri.\n        ///\n        ///   Such as\n        ///         \"image/picture1.jpg\"\n        ///    or\n        ///        \"pack://application:,,,/image/picture1.jpg\"\n        ///\n        /// </summary>\n        /// <param name=\"uriContent\">the uri maps to the Content File</param>\n        /// <returns>PackagePart or null</returns>\n        public static StreamResourceInfo GetContentStream(Uri uriContent)\n        {\n            ArgumentNullException.ThrowIfNull(uriContent);\n\n            if (uriContent.OriginalString == null)\n                throw new ArgumentException(SR.Format(SR.ArgumentPropertyMustNotBeNull, \"uriContent\", \"OriginalString\"));\n\n            if (uriContent.IsAbsoluteUri && !BaseUriHelper.IsPackApplicationUri(uriContent))\n            {\n                throw new ArgumentException(SR.NonPackAppAbsoluteUriNotAllowed);\n            }\n\n            ContentFilePart part = GetResourceOrContentPart(uriContent) as ContentFilePart;\n            return (part == null) ? null : new StreamResourceInfo(part.GetSeekableStream(), part.ContentType);\n        }\n\n        /// <summary>\n        /// Get PackagePart for a uri, the uri maps to a file which comes from the place\n        /// where the application was originally deployed.\n        ///\n        /// The accepted uri could be relative uri such as \"foo.jpg\"\n        ///\n        /// or  pack Uri, \"pack://siteoforigin:,,,/foo.jpg\"\n        ///","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs#L593-L629","documentation":"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.","triggerScenarios":"Calling GetContentStream with a Uri whose OriginalString is null, typically produced by uninitialized config values or deserialization.","commonSituations":"Content path settings missing at runtime; a bound Uri property never initialized before content loading runs.","solutions":["Build the Uri from a validated non-null string, e.g. new Uri(@\"Content\\help.htm\", UriKind.Relative)","Guard before calling: if (uri?.OriginalString == null) handle/throw","Fix the configuration or producer yielding the null-string Uri"],"exampleFix":"// before\nUri uri = GetContentPath(); // OriginalString == null\nvar sri = Application.GetContentStream(uri);\n\n// after\nvar uri = new Uri(\"Content/help.htm\", UriKind.Relative);\nvar sri = Application.GetContentStream(uri);","handlingStrategy":"validation","validationCode":"if (uri == null || uri.OriginalString == null)\n    return null; // or throw a clearer error\nvar sri = Application.GetContentStream(uri);","typeGuard":"static bool IsValidContentUri(Uri u) => u?.OriginalString != null;","tryCatchPattern":"try { sri = Application.GetContentStream(uri); }\ncatch (ArgumentException ex) { Log(ex); sri = null; }","preventionTips":["Validate content paths from configuration at startup","Construct Uris from non-null strings with UriKind.Relative","Check File.Exists/pack part presence before content loading in deployment-sensitive builds"],"tags":["wpf","uri","argument-validation","content-files"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}