{"record":{"id":"392d8092f0789f16","repo":"dotnet/wpf","slug":"sr-format-sr-argumentpropertymustnotbenull-resourcelocator","errorCode":null,"errorMessage":"SR.Format(SR.ArgumentPropertyMustNotBeNull,\"resourceLocator\", \"OriginalString\")","messagePattern":"SR\\.Format\\(SR\\.ArgumentPropertyMustNotBeNull,\"resourceLocator\", \"OriginalString\"\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs","lineNumber":352,"sourceCode":"            {\n                bool canCache;\n                return resources.FetchResource(resourceKey, allowDeferredResourceReference, mustReturnDeferredResourceReference, out canCache);\n            }\n        }\n\n        /// <summary>\n        /// Create logic tree from given resource Locator, and associate this\n        /// tree with the given component.\n        /// </summary>\n        /// <param name=\"component\">Root Element</param>\n        /// <param name=\"resourceLocator\">Resource Locator</param>\n        public static void LoadComponent(Object component, Uri resourceLocator)\n        {\n            ArgumentNullException.ThrowIfNull(component);\n            ArgumentNullException.ThrowIfNull(resourceLocator);\n\n            if (resourceLocator.OriginalString == null)\n                throw new ArgumentException(SR.Format(SR.ArgumentPropertyMustNotBeNull,\"resourceLocator\", \"OriginalString\"));\n\n            if (resourceLocator.IsAbsoluteUri)\n                throw new ArgumentException(SR.AbsoluteUriNotAllowed);\n\n            // Passed a relative Uri here.\n            // needs to resolve it to Pack://Application.\n            //..\\..\\ in the relative Uri will get stripped when creating the new Uri and resolving to the\n            //PackAppBaseUri, i.e. only relative Uri within the appbase are created here\n            Uri currentUri = new Uri(BaseUriHelper.PackAppBaseUri, resourceLocator);\n\n            //\n            // Generate the ParserContext from packUri\n            //\n            ParserContext pc = new ParserContext\n            {\n                BaseUri = currentUri\n            };\n","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs#L334-L370","documentation":"Application.LoadComponent(Object, Uri) validates the resourceLocator Uri before loading XAML. If the Uri's OriginalString is null it throws ArgumentException describing that resourceLocator.OriginalString must not be null. A Uri object can wrap a null string only via unsafe construction, so this is a defensive argument validation.","triggerScenarios":"Passing a Uri instance whose OriginalString is null into LoadComponent(Object component, Uri resourceLocator).","commonSituations":"Uri created through deserialization or interop with a null backing string; a default(Uri)-like flow assigning an uninitialized value that is later boxed into a property; binding a URI property that was never initialized.","solutions":["Ensure the Uri is created from a non-null string, e.g. new Uri(\"MyPage.xaml\", UriKind.Relative)","Guard the caller: skip LoadComponent when uri == null || uri.OriginalString == null","Fix the source of the null OriginalString (deserialization/property initialization)"],"exampleFix":"// before\nUri uri = GetUriSomehow(); // OriginalString == null\nApplication.LoadComponent(page, uri);\n\n// after\nvar uri = new Uri(\"MyPage.xaml\", UriKind.Relative);\nApplication.LoadComponent(page, uri);","handlingStrategy":"validation","validationCode":"if (uri == null || uri.OriginalString == null)\n    throw new ArgumentException(\"resourceLocator must have a non-null OriginalString\");\nApplication.LoadComponent(component, uri);","typeGuard":"static bool IsValidLocator(Uri u) => u?.OriginalString != null;","tryCatchPattern":"try { Application.LoadComponent(component, uri); }\ncatch (ArgumentException ex) { Log(ex); LoadFallbackComponent(); }","preventionTips":["Always construct Uri from literal/validated non-null strings","Validate Uri arguments at component boundaries before calling LoadComponent","Never pass Uris that came from unchecked deserialization"],"tags":["wpf","argument-validation","uri","null"],"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"}