stride3d/stride · error · InvalidOperationException

Failed to find mesh buffers while attempting to…

Error message

Failed to find mesh buffers while attempting to FetchBufferContentOrThrow. Make sure that the mesh is either an asset on disk, or has its buffer data attached to the buffer through 'AttachedReference'

What it means

FetchBufferContentOrThrow fetches the raw byte content of a mesh Buffer from its asset on disk or from data attached via AttachedReference. If TryFetchBufferContent returns null or empty, the buffer has no resolvable backing data, and this InvalidOperationException is thrown with guidance to attach data or keep the asset available.

Solutions

  1. Ensure the mesh is a serialized asset present at its AttachedReference Url, or manually set buffer.AttachedReference.Content with the raw index/vertex data.
  2. Include the mesh asset files in the build output/package.
  3. Call TryFetchBufferContent first if you want to handle missing data gracefully instead of throwing.
  4. Verify the IServiceRegistry passed in has the asset/ContentManager services registered.

Example fix

// before
var data = MeshExtension.FetchBufferContentOrThrow(runtimeOnlyBuffer, services); // throws
// after
var data = runtimeOnlyBuffer.AttachedReference?.Content ??
           MeshExtension.FetchBufferContentOrThrow(runtimeOnlyBuffer, services);
Defensive patterns

Strategy: try-catch

Validate before calling

var attached = buffer.AttachedReference;
bool hasData = (attached?.Content is { Length: > 0 }) ||
               (attached?.Url != null && services.SafeGetAsset(attached.Url) != null);

Type guard

bool HasFetchableContent(Buffer b) => b.AttachedReference?.Content is { Length: > 0 } || b.AttachedReference?.Url is not null;

Try / catch

try { data = MeshExtension.FetchBufferContentOrThrow(buffer, services); }
catch (InvalidOperationException ex)
{ log.Error("mesh buffer data unavailable: ensure asset packaged or AttachedReference.Content set", ex); }

Prevention

When it happens

Trigger: Calling MeshExtension.FetchBufferContentOrThrow on a buffer whose AttachedReference.Content is null/empty AND whose source asset (via AttachedReference Url/Id) cannot be found on disk or is not a supported mesh asset.

Common situations: Runtime-created buffers with no AttachedReference data (e.g. dynamic/gpu-written buffers); mesh assets deleted, moved, or not packaged with the build; running in an environment without the asset database (IServiceRegistry lacking asset services); reading geometry from a mesh that was never persisted.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Graphics/MeshExtension.cs:83

                return true;
            }

            // Compute next offset (if automatic)
            offset += elementSize;
        }

        result = default;
        return false;
    }

    /// <inheritdoc cref="TryFetchBufferContent"/>
    /// <remarks> Same as <see cref="TryFetchBufferContent"/> but throws on failure </remarks>
    internal static byte[] FetchBufferContentOrThrow(Buffer buffer, IServiceRegistry services)
    {
        var data = TryFetchBufferContent(buffer, services);
        if (data is null || data.Length == 0)
        {
            throw new InvalidOperationException(
                $"Failed to find mesh buffers while attempting to {nameof(FetchBufferContentOrThrow)}. " +
                $"Make sure that the mesh is either an asset on disk, or has its buffer data attached to the buffer through '{nameof(AttachedReference)}'\n");
        }

        return data;
    }

    /// <summary> Get buffer content from GPU, shared memory or disk </summary>
    internal static byte[]? TryFetchBufferContent(Buffer buffer, IServiceRegistry services)
    {
        var bufRef = AttachedReferenceManager.GetAttachedReference(buffer);
        if (bufRef?.Data != null && ((BufferData)bufRef.Data).Content is { } output)
            return output;

        // Try to load it from disk, a file provider is required, editor does not provide one
        if (bufRef?.Url != null && services.GetService<IDatabaseFileProviderService>() is {} provider && provider.FileProvider is not null)
        {
            // We have to create a new one without providing services to ensure that it dumps the graphics buffer data to the attached reference below

View on GitHub (pinned to 96fad776d2)