stride3d/stride · error · InvalidOperationException

Unable to create an instance of definition type

Error message

Unable to create an instance of definition type {definitionGenericDefinitionType.Name} for asset type {currentType.Name}.

What it means

GetDefinition found a matching generic definition type for a generic asset type, but Activator/MakeGenericType instantiation of the closed definition type threw (e.g. missing constructor or type-constraint violation). The inner exception carries the real cause; the message identifies the definition and asset types involved.

Solutions

  1. Ensure the generic definition type has a public parameterless constructor usable after MakeGenericType
  2. Check that the generic parameters satisfy the definition type's constraints
  3. Catch and inspect the inner exception to identify the failing instantiation step
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at sources/assets/Stride.Core.Assets.Quantum/AssetQuantumRegistry.cs:139 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at sources/assets/Stride.Core.Assets.Quantum/AssetQuantumRegistry.cs:139

            }

            if (currentType.IsGenericType)
            {
                // If we reach a generic type, we must check if we have a matching generic definition and if so, create a proper instance of this generic type.
                var assetGenericDefinitionType = currentType.GetGenericTypeDefinition();
                if (GenericNodeGraphDefinitionTypes.TryGetValue(assetGenericDefinitionType, out var definitionGenericDefinitionType))
                {
                    try
                    {
                        var definitionType = definitionGenericDefinitionType.MakeGenericType(currentType.GetGenericArguments());
                        definition = (AssetPropertyGraphDefinition)Activator.CreateInstance(definitionType)!;
                        // Register the (new) instance for this specific type so we don't have to do this again next time.
                        NodeGraphDefinitions.Add(assetType, definition);
                        return definition;
                    }
                    catch (Exception)
                    {
                        throw new InvalidOperationException($"Unable to create an instance of definition type {definitionGenericDefinitionType.Name} for asset type {currentType.Name}.");
                    }
                }
            }

            currentType = currentType.BaseType;
        }

        return NodeGraphDefinitions[typeof(Asset)];
    }
}

View on GitHub (pinned to 96fad776d2)