AvaloniaUI/Avalonia · error · ArgumentNullException
material
Error message
material
What it means
MaterialExtensions.ToImmutable throws ArgumentNullException(nameof(material)) when the IExperimentalAcrylicMaterial is null. It needs a non-null material to attempt the IMutableExperimentalAcrylicMaterial.ToImmutable() conversion or return the instance unchanged.
Source
Thrown at src/Avalonia.Base/Media/MaterialExtensions.cs:17
using System;
namespace Avalonia.Media
{
public static class MaterialExtensions
{
/// <summary>
/// Converts a brush to an immutable brush.
/// </summary>
/// <param name="material">The brush.</param>
/// <returns>
/// The result of calling <see cref="IMutableBrush.ToImmutable"/> if the brush is mutable,
/// otherwise <paramref name="material"/>.
/// </returns>
public static IExperimentalAcrylicMaterial ToImmutable(this IExperimentalAcrylicMaterial material)
{
_ = material ?? throw new ArgumentNullException(nameof(material));
return (material as IMutableExperimentalAcrylicMaterial)?.ToImmutable() ?? material;
}
}
}
View on GitHub (pinned to 11c5427268)
Solutions
- Null-check the material before calling ToImmutable.
- Initialize the material before use.
- Provide a default immutable acrylic material as a fallback.
Example fix
// before var imm = _acrylic.ToImmutable(); // _acrylic may be null // after var imm = _acrylic is null ? ExperimentalAcrylicMaterial.Default : _acrylic.ToImmutable();
Defensive patterns
Strategy: validation
Validate before calling
if (material is null)
throw new ArgumentNullException(nameof(material));
var imm = material.ToImmutable(); Prevention
- Null-check materials before calling ToImmutable.
- Initialize acrylic materials before use.
- Provide a default immutable material as a fallback.
When it happens
Trigger: Calling material.ToImmutable() (the extension method) on a null IExperimentalAcrylicMaterial reference.
Common situations: A null acrylic material field/property being flattened; binding that resolved to null; default-constructed brushes before initialization.
Related errors
- Invalid brush string: '{s}'.
- Unknown CacheMode: {s}
- Invalid color string: '{s}'.
- Invalid color string: '{s.ToString()}'.
- Unable to parse effect: {s}
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/8e88c35c31187f2b.
Report an issue: GitHub.