{"record":{"id":"a79b9ef9228cc2af","repo":"dotnet/wpf","slug":"sr-format-sr-resourcedictionaryloadfromfailure-value-null","errorCode":null,"errorMessage":"SR.Format(SR.ResourceDictionaryLoadFromFailure, value == null ? \"''\" : value.ToString())","messagePattern":"SR\\.Format\\(SR\\.ResourceDictionaryLoadFromFailure, value == null \\? \"''\" : value\\.ToString\\(\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs","lineNumber":136,"sourceCode":"                return _mergedDictionaries;\n            }\n        }\n\n        ///<summary>\n        ///     Uri to load this resource from, it will clear the current state of the ResourceDictionary\n        ///</summary>\n        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]\n        public Uri Source\n        {\n            get\n            {\n                return _source;\n            }\n            set\n            {\n                if (value == null || String.IsNullOrEmpty(value.OriginalString))\n                {\n                    throw new ArgumentException(SR.Format(SR.ResourceDictionaryLoadFromFailure, value == null ? \"''\" : value.ToString()));\n                }\n\n                ResourceDictionaryDiagnostics.RemoveResourceDictionaryForUri(_source, this);\n\n                ResourceDictionarySourceUriWrapper uriWrapper = value as ResourceDictionarySourceUriWrapper;\n\n                Uri sourceUri;\n\n                // If the Uri we received is a ResourceDictionarySourceUriWrapper it means\n                // that it is being passed down by the Baml parsing code, and it is trying to give us more\n                // information to avoid possible ambiguities in assembly resolving. Use the VersionedUri\n                // to resolve, and the set _source to the OriginalUri so we don't change the return of Source property.\n                // The versioned Uri is not stored, if the version info is needed while debugging, once this method\n                // returns _reader should be set, from there BamlSchemaContext.LocalAssembly contains the version info.\n                if (uriWrapper == null)\n                {\n                    _source = value;\n                    sourceUri = _source;","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs#L118-L154","documentation":"ResourceDictionary.Source only accepts a non-null, non-empty absolute Uri; setting it to null or an empty Uri throws an ArgumentException with SR.ResourceDictionaryLoadFromFailure, echoing the (empty) value. The library throws this because it cannot begin loading a dictionary from an empty source.","triggerScenarios":"Assigning ResourceDictionary.Source = null or Source = new Uri(\"\") (empty OriginalString) in code, or a XAML/binding pipeline that resolves an empty pack URI into Source.","commonSituations":"Merged-dictionary setup in App.xaml code-behind where a config/appsetting string for a resource path is empty or null; dynamically building ResourceDictionaries at startup.","solutions":["Supply a valid, non-empty absolute Uri (typically a pack URI like new Uri(\"pack://application:,,,/Themes/Theme.xaml\")).","Validate the source string from configuration before constructing the Uri.","Guard the assignment: only set Source when the Uri and its OriginalString are non-empty."],"exampleFix":"// before\ndictionary.Source = new Uri(config[\"ThemePath\"] ?? \"\");\n// after\nstring themePath = config[\"ThemePath\"];\nif (!string.IsNullOrEmpty(themePath))\n    dictionary.Source = new Uri(themePath, UriKind.Absolute);","handlingStrategy":"validation","validationCode":"if (source == null || string.IsNullOrEmpty(source.OriginalString)) throw new ArgumentException(\"Resource dictionary Source must be a non-empty Uri\", nameof(source));","typeGuard":"bool IsValidSource(Uri source) => source != null && !string.IsNullOrEmpty(source.OriginalString);","tryCatchPattern":"try { rd.Source = new Uri(path, UriKind.Absolute); } catch (ArgumentException ex) when (ex.Message.Contains(\"ResourceDictionaryLoadFromFailure\") || ex.Message.Contains(\"Load from\")) { log.Error(\"Invalid dictionary source\", ex); }","preventionTips":["Validate configuration strings for resource paths at startup, fail fast with a clear message","Use Uri.TryCreate with UriKind.Absolute before assigning Source","Never assign null to Source; create a new ResourceDictionary instead"],"tags":["wpf","resourcedictionary","uri"],"backgroundTag":"empty-required-field","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"}