dotnet/wpf · error · ArgumentNullException
ArgumentNullException(nameof(assemblyPath))
Error message
ArgumentNullException(nameof(assemblyPath))
What it means
XamlTypeMapper.SetAssemblyPath throws ArgumentNullException when assemblyPath is null. The path is used to locate and load the assembly during XAML parsing; a null path would break resolution later, so the API rejects it up front. Note it also rejects the empty string as a separate error.
Solutions
- Pass the full path to the assembly file as the second argument
- Ensure the assembly actually exists on disk and its path was resolved before calling
- Use Assembly.Location (checked for non-empty) to obtain the path
Example fix
// before string path = settings.GetPath(assemblyName); // null when not configured mapper.SetAssemblyPath(assemblyName, path); // after string path = settings.GetPath(assemblyName); if (path == null) path = Assembly.ReflectionOnlyLoad(assemblyName).Location; mapper.SetAssemblyPath(assemblyName, path);
Defensive patterns
Strategy: validation
Validate before calling
if (assemblyPath == null || !File.Exists(assemblyPath))
throw new FileNotFoundException("Assembly path missing", assemblyPath);
mapper.SetAssemblyPath(assemblyName, assemblyPath); Type guard
bool IsValidAssemblyPath(string path) => !string.IsNullOrEmpty(path) && File.Exists(path);
Try / catch
try
{
mapper.SetAssemblyPath(assemblyName, assemblyPath);
}
catch (ArgumentNullException ex) when (ex.ParamName == "assemblyPath")
{
log.LogError(ex, "No disk path registered for {Assembly}", assemblyName);
} Prevention
- Verify the assembly exists on disk before registering its path
- Resolve paths with Path.GetFullPath and check File.Exists
- Handle missing config entries for assembly locations explicitly
When it happens
Trigger: Calling SetAssemblyPath(assemblyName, null) — often when the path comes from a settings file, registry value, or probe that returned null because the assembly wasn't found.
Common situations: Custom designer/parse hosts mapping assemblies to disk paths; deployment changes where an assembly's registered path entry is missing; tests passing null placeholders.
Related errors
- ArgumentNullException(nameof(assemblyName))
- ArgumentNullException(nameof(assemblyNames))
- ArgumentNullException(nameof(clrNamespace))
- ArgumentNullException(nameof(localName))
- ArgumentNullException(nameof(propertyName))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/fe2f1050b7e0267e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs:186
/// This allows specifying a path to use when loading the named assembly.
/// </summary>
/// <param name="assemblyName">
/// The short name of the assembly, with no extension or path specified
/// </param>
/// <param name="assemblyPath">
/// The file path of the assembly
/// </param>
public void SetAssemblyPath(
string assemblyName,
string assemblyPath)
{
if( null == assemblyName )
{
throw new ArgumentNullException(nameof(assemblyName));
}
if( null == assemblyPath )
{
throw new ArgumentNullException(nameof(assemblyPath));
}
if (assemblyPath == string.Empty)
{
_lineNumber = 0; // Public API, so we don't know the line number.
ThrowException(nameof(SR.ParserBadAssemblyPath));
}
if (assemblyName == string.Empty)
{
_lineNumber = 0; // Public API, so we don't know the line number.
ThrowException(nameof(SR.ParserBadAssemblyName));
}
string asmName = assemblyName.ToUpper(CultureInfo.InvariantCulture);
lock (_assemblyPathTable)
{
_assemblyPathTable[asmName] = assemblyPath;
}
View on GitHub (pinned to 81131a70a4)