dotnet/wpf · error · ArgumentNullException
ArgumentNullException(nameof(assemblyNames))
Error message
ArgumentNullException(nameof(assemblyNames))
What it means
The XamlTypeMapper(string[] assemblyNames) constructor validates its required argument and throws ArgumentNullException when assemblyNames is null. The mapper needs a list of assemblies to resolve XAML namespace/types, so a null list is rejected immediately at construction.
Solutions
- Pass a non-null string array, e.g. new XamlTypeMapper(Array.Empty<string>()) if no assemblies are needed.
- Null-check the value feeding the constructor and provide a default assembly list before calling it.
- Fix the configuration/source so the assembly-names collection is populated.
- Wrap construction in try/catch for ArgumentNullException to surface a clearer diagnostic in plug-in scenarios.
Example fix
// before
var mapper = new XamlTypeMapper(GetAssemblyNamesFromConfig()); // null -> ArgumentNullException
// after
string[] assemblies = GetAssemblyNamesFromConfig() ?? new[] { typeof(Window).Assembly.FullName };
var mapper = new XamlTypeMapper(assemblies); Defensive patterns
Strategy: validation
Validate before calling
if (assemblyNames is null)
throw new ArgumentException("assemblyNames must not be null; pass an empty array if none.", nameof(assemblyNames));
var mapper = new System.Windows.Markup.XamlTypeMapper(assemblyNames); Type guard
static bool IsValidAssemblyNames(string[] names) => names != null;
Try / catch
try { var mapper = new XamlTypeMapper(assemblyNames); }
catch (ArgumentNullException ex) { /* log ex.ParamName and supply defaults */ } Prevention
- Null-check collections sourced from configuration before passing them to constructors.
- Default to Array.Empty<string>() rather than null when a list may be absent.
- Validate DI-provided or config-provided arrays at the composition boundary.
- Use ArgumentNullException.ThrowIfNull on your own inputs early to fail fast with clear diagnostics.
When it happens
Trigger: Calling new XamlTypeMapper(null), typically when the assembly list is built dynamically (e.g. from configuration) and the source collection came back null. Source: XamlTypeMapper.cs:55-60.
Common situations: Config or app-settings lookups returning null for the assembly list; refactoring that drops a default array; dependency-injection wiring where a null collection is passed through; code paths compiled under the conditional #if block where the ctor is available.
Related errors
- ArgumentNullException(nameof(assemblyName))
- ArgumentNullException(nameof(assemblyPath))
- ArgumentNullException(nameof(clrNamespace))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/cad1c2529bb62cd9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs:55
internal class XamlTypeMapper
#else
public partial class XamlTypeMapper
#endif
{
#region Public
#region Methods
#if !PBTCOMPILER
/// <summary>
/// Constructor
/// </summary>
/// <param name="assemblyNames">Assemblies XamlTypeMapper should use when resolving XAML</param>
public XamlTypeMapper(string[] assemblyNames)
{
if(null == assemblyNames)
{
throw new ArgumentNullException( nameof(assemblyNames));
}
_assemblyNames = assemblyNames;
_namespaceMaps = null;
}
#endif
/// <summary>
/// Constructor
/// </summary>
/// <param name="assemblyNames">Assemblies XamlTypeMapper should use when resolving XAML</param>
/// <param name="namespaceMaps">NamespaceMap the XamlTypeMapper should use when resolving XAML</param>
public XamlTypeMapper(
string[] assemblyNames,
NamespaceMapEntry[] namespaceMaps)
{
if(null == assemblyNames)
{View on GitHub (pinned to 81131a70a4)