dotnet/wpf · error · ArgumentNullException
ArgumentNullException(nameof(value))
Error message
ArgumentNullException(nameof(value))
What it means
The TypeExtension.TypeName setter throws ArgumentNullException when assigned null. Assigning TypeName is meant to switch the extension to name-based resolution; null would leave the extension in an inconsistent state, so the library rejects it.
Solutions
- Assign a non-null string, or create a new TypeExtension instance instead of nulling properties.
- Guard: if (value != null) ext.TypeName = value;
- Use the Type property with a real Type when the name is unknown.
- Wrap in try/catch ArgumentNullException if null assignment is possible in legacy code paths.
Example fix
// before ext.TypeName = GetTypeName() ; // GetTypeName() may return null // after var name = GetTypeName(); if (name != null) ext.TypeName = name;
Defensive patterns
Strategy: type-guard
Validate before calling
if (name is null) throw new ArgumentException("TypeName cannot be null.");
ext.TypeName = name; Type guard
static bool IsNonEmpty(string? s) => !string.IsNullOrEmpty(s);
Try / catch
try { ext.TypeName = value; }
catch (ArgumentNullException) { ext.TypeName = string.Empty; log.Warn("Null TypeName ignored."); } Prevention
- Never reset markup-extension properties to null; recreate the instance instead.
- Enable nullable reference types so null assignments surface at compile time.
When it happens
Trigger: Executing typeExtension.TypeName = null; on any TypeExtension instance.
Common situations: Code that clears markup-extension settings in bulk with null values; reflection-based serializers or designers assigning null for an absent attribute value.
Related errors
- ArgumentNullException(nameof(clrNamespace))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
- ArgumentNullException(nameof(newNamespace))
- ArgumentNullException(nameof(oldNamespace))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/7229b8d52dc71b97.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/TypeExtension.cs:95
{
throw new InvalidOperationException(SR.Format(SR.MarkupExtensionTypeNameBad, _typeName));
}
return _type;
}
/// <summary>
/// The typename represented by this markup extension. The name has the format
/// Prefix:Typename, where Prefix is the xml namespace prefix for this type.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string TypeName
{
get => _typeName;
set
{
// Reset the type so ProvideValue does not use the existing type.
_typeName = value ?? throw new ArgumentNullException(nameof(value));
_type = null;
}
}
/// <summary>
/// The type represented by this markup extension.
/// </summary>
[DefaultValue(null)]
[ConstructorArgument("type")]
public Type Type
{
get => _type;
set
{
// Reset the type name so ProvideValue does not use the existing type name.
_type = value ?? throw new ArgumentNullException(nameof(value));
_typeName = null;
}View on GitHub (pinned to 81131a70a4)