{"record":{"id":"9ac07bb64be2dbf1","repo":"dotnet/wpf","slug":"sr-themedictionaryextension-name","errorCode":null,"errorMessage":"SR.ThemeDictionaryExtension_Name","messagePattern":"SR\\.ThemeDictionaryExtension_Name","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeDictionaryExtension.cs","lineNumber":68,"sourceCode":"\n        #endregion\n\n        #region Public Methods\n\n        /// <summary>\n        ///  Return an object that should be set on the targetObject's targetProperty\n        ///  for this markup extension.  For ThemeDictionaryExtension, this is the Uri\n        ///  pointing to theme specific dictionary in the specified assembly by AssemblyName.\n        /// </summary>\n        /// <param name=\"serviceProvider\">ServiceProvider that can be queried for services.</param>\n        /// <returns>\n        ///  The object to set on this property.\n        /// </returns>\n        public override object ProvideValue(IServiceProvider serviceProvider)\n        {\n            if (string.IsNullOrEmpty(AssemblyName))\n            {\n                throw new InvalidOperationException(SR.ThemeDictionaryExtension_Name);\n            }\n\n            IProvideValueTarget provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;\n            if( provideValueTarget == null )\n            {\n                throw new InvalidOperationException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, \"IProvideValueTarget\" ));\n            }\n                \n            object targetObject = provideValueTarget.TargetObject;\n            object targetProperty = provideValueTarget.TargetProperty;\n\n            ResourceDictionary dictionary = targetObject as ResourceDictionary;\n            PropertyInfo propertyInfo = targetProperty as PropertyInfo;\n\n            // Allow targetProperty to be null or ResourceDictionary.Source\n            if (dictionary == null || (targetProperty != null && propertyInfo != SourceProperty))\n            {\n                throw new InvalidOperationException(SR.ThemeDictionaryExtension_Source);","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeDictionaryExtension.cs#L50-L86","documentation":"ThemeDictionaryExtension.ProvideValue requires the AssemblyName property to identify which assembly's theme dictionaries to reference. When AssemblyName is null or empty at evaluation time, it throws InvalidOperationException with SR.ThemeDictionaryExtension_Name.","triggerScenarios":"Using {ThemeDictionary ...} in XAML without supplying the AssemblyName (the constructor string argument or the AssemblyName property); a binding or missing constructor parameter leaves AssemblyName unset when ProvideValue runs.","commonSituations":"Typo'd or missing argument in the markup extension usage in a ResourceDictionary; programmatically constructed ThemeDictionaryExtension where only ProvideValue is called without setting AssemblyName.","solutions":["Pass the assembly name in markup: <ResourceDictionary Source=\"{ThemeDictionary PresentationFramework.Aero2}\"/>.","Set the AssemblyName property on the extension before calling ProvideValue programmatically.","Validate string.IsNullOrEmpty(ext.AssemblyName) before invoking ProvideValue."],"exampleFix":"// before\nvar ext = new ThemeDictionaryExtension();\nvar uri = (Uri)ext.ProvideValue(sp); // throws: name missing\n// after\nvar ext = new ThemeDictionaryExtension(\"MyApp.Themes\");\nvar uri = (Uri)ext.ProvideValue(sp);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(ext.AssemblyName))\n    throw new InvalidOperationException(\"ThemeDictionaryExtension.AssemblyName must be set before ProvideValue.\");","typeGuard":null,"tryCatchPattern":"try { return (Uri)ext.ProvideValue(sp); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"AssemblyName\") || ex.Message.Contains(\"name\")) { return null; }","preventionTips":["Always supply the constructor argument to {ThemeDictionary ...}.","Keep the assembly name in sync when renaming projects.","XAML linters can flag ThemeDictionary usages with no argument."],"tags":["wpf","markup-extension","theme"],"backgroundTag":"missing-required-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"}