dotnet/wpf · error · InvalidOperationException

SR.ThemeDictionaryExtension_Name

Error message

SR.ThemeDictionaryExtension_Name

What it means

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.

Solutions

  1. Pass the assembly name in markup: <ResourceDictionary Source="{ThemeDictionary PresentationFramework.Aero2}"/>.
  2. Set the AssemblyName property on the extension before calling ProvideValue programmatically.
  3. Validate string.IsNullOrEmpty(ext.AssemblyName) before invoking ProvideValue.

Example fix

// before
var ext = new ThemeDictionaryExtension();
var uri = (Uri)ext.ProvideValue(sp); // throws: name missing
// after
var ext = new ThemeDictionaryExtension("MyApp.Themes");
var uri = (Uri)ext.ProvideValue(sp);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(ext.AssemblyName))
    throw new InvalidOperationException("ThemeDictionaryExtension.AssemblyName must be set before ProvideValue.");

Try / catch

try { return (Uri)ext.ProvideValue(sp); }
catch (InvalidOperationException ex) when (ex.Message.Contains("AssemblyName") || ex.Message.Contains("name")) { return null; }

Prevention

When it happens

Trigger: 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.

Common situations: Typo'd or missing argument in the markup extension usage in a ResourceDictionary; programmatically constructed ThemeDictionaryExtension where only ProvideValue is called without setting AssemblyName.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/9ac07bb64be2dbf1. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ThemeDictionaryExtension.cs:68

        #endregion

        #region Public Methods

        /// <summary>
        ///  Return an object that should be set on the targetObject's targetProperty
        ///  for this markup extension.  For ThemeDictionaryExtension, this is the Uri
        ///  pointing to theme specific dictionary in the specified assembly by AssemblyName.
        /// </summary>
        /// <param name="serviceProvider">ServiceProvider that can be queried for services.</param>
        /// <returns>
        ///  The object to set on this property.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (string.IsNullOrEmpty(AssemblyName))
            {
                throw new InvalidOperationException(SR.ThemeDictionaryExtension_Name);
            }

            IProvideValueTarget provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
            if( provideValueTarget == null )
            {
                throw new InvalidOperationException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, "IProvideValueTarget" ));
            }
                
            object targetObject = provideValueTarget.TargetObject;
            object targetProperty = provideValueTarget.TargetProperty;

            ResourceDictionary dictionary = targetObject as ResourceDictionary;
            PropertyInfo propertyInfo = targetProperty as PropertyInfo;

            // Allow targetProperty to be null or ResourceDictionary.Source
            if (dictionary == null || (targetProperty != null && propertyInfo != SourceProperty))
            {
                throw new InvalidOperationException(SR.ThemeDictionaryExtension_Source);

View on GitHub (pinned to 81131a70a4)