dotnet/wpf · error · ArgumentException

assembly

Error message

assembly

What it means

When expanding a clr-namespace URI, Baml2006Reader parses the 'assembly=' keyword from the URI string; if the keyword before '=' is not exactly 'assembly' it throws ArgumentException wrapping SR.AssemblyTagMissing. The URI's namespace-to-assembly directive is malformed.

Solutions

  1. Fix the URI to use the exact keyword 'assembly' before '=' in the clr-namespace mapping.
  2. Validate the full form: clr-namespace:<Namespace>[;assembly=<AssemblyName>].
  3. Check for typos or locale/renaming refactors that altered the keyword in .xaml files.
  4. If generating URIs in code/tests, build them with a helper that inserts ";assembly=" verbatim.

Example fix

// before
xmlns:local="clr-namespace:App.Controls;assemly=App"
// after
xmlns:local="clr-namespace:App.Controls;assembly=App"
Defensive patterns

Strategy: validation

Validate before calling

// Validate clr-namespace URI grammar before handing it to the reader
bool IsValidClrNamespaceUri(string uri) =>
    !uri.StartsWith("clr-namespace:") ||
    uri.Split(';').Skip(1).All(p => !p.Contains('=') || p.Split('=')[0].Trim() == "assembly");

Try / catch

try
{
    // resolve namespace URI via reader/schema context
}
catch (ArgumentException ex) when (ex.Message.Contains("assembly"))
{
    throw new FormatException($"clr-namespace URI must use 'assembly=' keyword: {uriInput}", ex);
}

Prevention

When it happens

Trigger: Logic_GetFullXmlns is given a URI like 'clr-namespace:Foo;assemly=App' (misspelled or otherwise not the ordinal string "assembly" between the ';' and '=').

Common situations: Typo in XAML xmlns declarations (e.g. 'assemblies=', 'asm='); copy-pasted URI fragments; tooling that builds clr-namespace URIs programmatically with a wrong keyword.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs:2089

                    {
                        // We need to append local assembly

                        return uriInput + ((_settings.LocalAssembly != null)
                                                ? $";assembly={GetAssemblyNameForNamespace(_settings.LocalAssembly)}"
                                                : String.Empty);
                    }
                    else
                    {
                        int assemblyKeywordStartIdx = semicolonIdx + 1;
                        int equalIdx = uriInput.IndexOf('=');
                        if (-1 == equalIdx)
                        {
                            throw new ArgumentException(SR.Format(SR.MissingTagInNamespace, "=", uriInput));
                        }
                        ReadOnlySpan<char> keyword = uriInput.AsSpan(assemblyKeywordStartIdx, equalIdx - assemblyKeywordStartIdx);
                        if (!keyword.Equals("assembly", StringComparison.Ordinal))
                        {
                            throw new ArgumentException(SR.Format(SR.AssemblyTagMissing, "assembly", uriInput));
                        }
                        ReadOnlySpan<char> assemblyName = uriInput.AsSpan(equalIdx + 1);
                        if (assemblyName.TrimStart().IsEmpty)
                        {
                            return string.Concat(uriInput, GetAssemblyNameForNamespace(_settings.LocalAssembly));
                        }
                    }
                }
            }

            return uriInput;
        }

        // Providing the assembly short name may lead to ambiguity between two versions of the same assembly, but we need to
        // keep it this way since it is exposed publicly via the Namespace property, Baml2006ReaderInternal provides the full Assembly name.
        internal virtual ReadOnlySpan<char> GetAssemblyNameForNamespace(Assembly assembly)
        {
            return ReflectionUtils.GetAssemblyPartialName(assembly);

View on GitHub (pinned to 81131a70a4)