{"record":{"id":"0bc9d06246ac0cdd","repo":"dotnet/wpf","slug":"sr-format-sr-argumentpropertymustnotbenull-uriremote","errorCode":null,"errorMessage":"SR.Format(SR.ArgumentPropertyMustNotBeNull, \"uriRemote\", \"OriginalString\")","messagePattern":"SR\\.Format\\(SR\\.ArgumentPropertyMustNotBeNull, \"uriRemote\", \"OriginalString\"\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs","lineNumber":640,"sourceCode":"        /// <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        ///\n        /// </summary>\n        /// <param name=\"uriRemote\">the uri maps to the resource</param>\n        /// <returns>PackagePart or null</returns>\n        public static StreamResourceInfo GetRemoteStream(Uri uriRemote)\n        {\n            SiteOfOriginPart sooPart = null;\n\n            ArgumentNullException.ThrowIfNull(uriRemote);\n\n            if (uriRemote.OriginalString == null)\n                throw new ArgumentException(SR.Format(SR.ArgumentPropertyMustNotBeNull, \"uriRemote\", \"OriginalString\"));\n\n            if (uriRemote.IsAbsoluteUri)\n            {\n                if (!BaseUriHelper.SiteOfOriginBaseUri.IsBaseOf(uriRemote))\n                {\n                    throw new ArgumentException(SR.NonPackSooAbsoluteUriNotAllowed);\n                }\n            }\n\n            Uri resolvedUri = BindUriHelper.GetResolvedUri(BaseUriHelper.SiteOfOriginBaseUri, uriRemote);\n\n            Uri packageUri = PackUriHelper.GetPackageUri(resolvedUri);\n            Uri partUri = PackUriHelper.GetPartUri(resolvedUri);\n\n            //\n            // SiteOfOriginContainer must have been added into the package cache, the code should just\n            // take use of that SiteOfOriginContainer instance, instead of creating a new instance here.\n            //","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs#L622-L658","documentation":"GetRemoteStream validates that the Uri's OriginalString is not null before resolving a site-of-origin resource. A Uri can be constructed such that OriginalString is null (e.g. default(Uri) survived the null check via serialization or UriKind.RelativeOrRelative tricks), and WPF treats that as an invalid argument. This guards the subsequent resolution logic from a malformed Uri instance.","triggerScenarios":"Calling Application.GetRemoteStream with a Uri instance whose OriginalString is null — typically a Uri built through unusual paths (deserialization, default struct) rather than a normal constructor, since the constructor normally throws on null input.","commonSituations":"Uris round-tripped through serialization/formatters that skipped validation; reflection-created Uri instances; defensive check rarely hit because ArgumentNullException fires first on true nulls.","solutions":["Ensure the Uri is constructed via a normal Uri constructor with a non-null string before passing it","Check uriRemote?.OriginalString != null before calling GetRemoteStream","Re-create the Uri from its string form if it came from deserialization","If the value may be absent, skip the call or use a relative Uri with UriKind.Relative"],"exampleFix":"// before\nApplication.GetRemoteStream(maybeUri);\n// after\nif (maybeUri?.OriginalString != null)\n    Application.GetRemoteStream(maybeUri);","handlingStrategy":"type-guard","validationCode":"bool hasString(Uri u) => u?.OriginalString != null;","typeGuard":"bool HasOriginalString(Uri u) => u is Uri uri && uri.OriginalString is string s;","tryCatchPattern":"try { Application.GetRemoteStream(uri); } catch (ArgumentException ex) { /* rebuild uri from its string form */ }","preventionTips":["Construct Uris only via standard constructors","Re-create Uris after deserialization","Treat deserialized Uri instances as suspect"],"tags":["wpf","uri","null-argument","argument","resources"],"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"}