dotnet/wpf · error · ArgumentNullException

ArgumentNullException(nameof(assemblyName))

Error message

ArgumentNullException(nameof(assemblyName))

What it means

XamlTypeMapper.AddMappingProcessingInstruction validates its clrNamespace and assemblyName parameters and throws ArgumentNullException when assemblyName is null. This API adds a <?Mapping ...?> processing instruction equivalent to the mapper's table so ClrNamespace URIs resolve to assemblies. The library throws immediately to fail fast on invalid mapping input before building a ClrNamespaceAssemblyPair.

Solutions

  1. Pass a non-null assembly name string as the third argument to AddMappingProcessingInstruction
  2. Verify the variable feeding assemblyName is initialized; add a null check or coalesce to a default assembly
  3. If the assembly may not be known, resolve it via Assembly.GetName().Name instead of passing null

Example fix

// before
mapper.AddMappingProcessingInstruction(xmlNamespace, clrNamespace, null);
// after
mapper.AddMappingProcessingInstruction(xmlNamespace, clrNamespace, "MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
Defensive patterns

Strategy: validation

Validate before calling

if (xmlNamespace == null) throw new ArgumentException("xmlNamespace required");
if (clrNamespace == null) throw new ArgumentException("clrNamespace required");
if (assemblyName == null) throw new ArgumentException("assemblyName required");
mapper.AddMappingProcessingInstruction(xmlNamespace, clrNamespace, assemblyName);

Type guard

bool IsValidMappingArgs(string clrNamespace, string assemblyName) => !string.IsNullOrEmpty(clrNamespace) && !string.IsNullOrEmpty(assemblyName);

Try / catch

try
{
    mapper.AddMappingProcessingInstruction(xmlNs, clrNs, asmName);
}
catch (ArgumentNullException ex)
{
    log.LogError(ex, "Mapping PI arguments incomplete: {Param}", ex.ParamName);
}

Prevention

When it happens

Trigger: Calling XamlTypeMapper.AddMappingProcessingInstruction(xmlNamespace, clrNamespace, assemblyName) with a null assemblyName argument, e.g. when the assembly string is built dynamically from config or reflection and comes back null.

Common situations: Programmatic XAML mapping setup where the assembly name is read from configuration or a dictionary lookup that returns null; refactoring that renamed an assembly constant to null; WPF parser extension code building mapping instructions at runtime.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs:147

        /// <param name="assemblyName">
        /// The "PresentationFramework" argument in the mapping PI example.
        /// </param>
        public void AddMappingProcessingInstruction(
            string  xmlNamespace,
            string  clrNamespace,
            string  assemblyName )
        {
            if( null == xmlNamespace )
            {
                throw new ArgumentNullException(nameof(xmlNamespace));
            }
            if( null == clrNamespace )
            {
                throw new ArgumentNullException(nameof(clrNamespace));
            }
            if( null == assemblyName )
            {
                throw new ArgumentNullException(nameof(assemblyName));
            }

            // Parameter validation : Check for String.Empty as well?

            // Add mapping to the table keyed by xmlNamespace
            ClrNamespaceAssemblyPair pair = new ClrNamespaceAssemblyPair(clrNamespace, assemblyName);
            PITable[xmlNamespace] = pair;

            // Add mapping to the table keyed by assembly and clrnamespace
            string upperAssemblyName = assemblyName.ToUpper(
                                              TypeConverterHelper.InvariantEnglishUS);
            String fullName = $"{clrNamespace}#{upperAssemblyName}";

            _piReverseTable[fullName] = xmlNamespace;

            // Add mapping to the SchemaContext
            _schemaContext?.SetMappingProcessingInstruction(xmlNamespace, pair);
        }

View on GitHub (pinned to 81131a70a4)