stride3d/stride · error · ArgumentNullException

resource

Error message

resource

What it means

The GraphicsResourceLink constructor requires the allocated GraphicsResourceBase to be non-null; passing null throws ArgumentNullException with parameter name 'resource'. A link exists solely to hold a resource plus its reference counters, so a null resource is meaningless.

Solutions

  1. Ensure the resource creation call succeeded before constructing the link.
  2. Add a null check or validation at the creation site so nulls never reach the link constructor.

Example fix

// before
var link = new GraphicsResourceLink(CreateResourceMaybeNull());
// after
var res = CreateResourceMaybeNull() ?? throw new InvalidOperationException("resource creation failed");
var link = new GraphicsResourceLink(res);
Defensive patterns

Strategy: validation

Validate before calling

var res = CreateResource();
if (res is null) throw new InvalidOperationException("resource creation failed");
var link = new GraphicsResourceLink(res);

Type guard

bool HasResource(GraphicsResourceBase r) => r is not null;

Try / catch

try { link = new GraphicsResourceLink(resource); }
catch (ArgumentNullException ex) { log.Error("null resource", ex); throw; }

Prevention

When it happens

Trigger: Calling new GraphicsResourceLink(null), typically indirectly when an allocator cache entry is created from a resource lookup that returned null.

Common situations: Failed resource creation returning null yet being linked anyway; refactoring that removed a null check before constructing the link; reflection/DI constructing links without a resource.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/09c78b04b155023e. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Graphics/GraphicsResourceLink.cs:21

using System;

namespace Stride.Graphics;

/// <summary>
///   An object linking a Graphics Resource allocated by a <see cref="GraphicsResourceAllocator"/>
///   and providing allocation information.
/// </summary>
public sealed class GraphicsResourceLink
{
    /// <summary>
    ///   Initializes a new instance of the <see cref="GraphicsResourceLink"/> class.
    /// </summary>
    /// <param name="resource">The allocated Graphics Resource.</param>
    /// <exception cref="ArgumentNullException"><paramref name="resource"/> is <see langword="null"/>.</exception>
    internal GraphicsResourceLink(GraphicsResourceBase resource)
    {
        Resource = resource ?? throw new ArgumentNullException(nameof(resource));
    }


    /// <summary>
    ///   Gets the allocated Graphics Resource.
    /// </summary>
    public GraphicsResourceBase Resource { get; }

    /// <summary>
    ///   Gets the last time the Graphics Resource was accessed.
    /// </summary>
    public DateTime LastAccessTime { get; internal set; }

    /// <summary>
    ///   Gets the total number of times the Graphics Resource has been accessed (including Increment and Decrement).
    /// </summary>
    public long AccessTotalCount { get; internal set; }

View on GitHub (pinned to 96fad776d2)