stride3d/stride · error · InvalidOperationException
The associated asset type does not have a public…
Error message
The associated asset type does not have a public parameterless constructor.
What it means
Stride's DefaultAssetFactory<T>.New() creates a new instance of the associated asset type T. Before instantiating, it verifies that T exposes a public parameterless constructor via reflection; if not, it throws this InvalidOperationException because the factory cannot construct the asset.
Solutions
- Add a public parameterless constructor to the asset type used as T
- Ensure the type is concrete (not abstract) and the ctor is public
- Use a factory/type that supports constructor arguments instead of DefaultAssetFactory
Example fix
// before
public class MyAsset : Asset
{
public MyAsset(string name) { Name = name; }
}
// after
public class MyAsset : Asset
{
public MyAsset() { }
public MyAsset(string name) { Name = name; }
} Defensive patterns
Strategy: validation
Validate before calling
if (typeof(T).GetConstructor(Type.EmptyTypes) == null) throw new InvalidOperationException($"{typeof(T)} needs a public parameterless ctor"); Type guard
static bool HasDefaultCtor<T>() => typeof(T).GetConstructor(Type.EmptyTypes) != null;
Try / catch
try { asset = factory.New(); } catch (InvalidOperationException ex) { log.Error(ex.Message); } Prevention
- Always define a public parameterless constructor on Asset subclasses
- Keep asset types concrete and simple (data holders)
- Add a unit test that instantiates every registered asset type via New()
When it happens
Trigger: Calling New() on a factory whose generic type T (an Asset subclass) has no public parameterless constructor — e.g. the type only defines constructors with parameters or its parameterless constructor is private/internal.
Common situations: Registering a custom asset type in the asset factory system where the author added a convenience constructor with required parameters and removed the implicit default constructor; abstract types; compiler-generated types.
Related errors
- Type [ ] is not a primitive
- Type [ ] is not a primitive
- Type has no empty ctor
- Can not construct gizmo of type
- Unable to find the base
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/16a536859e8c8b33.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/DefaultAssetFactory.cs:22
namespace Stride.Core.Assets;
/// <summary>
/// An implementation of the <see cref="AssetFactory{T}"/> class that uses the default public parameterless constructor
/// of the associated asset type.
/// </summary>
/// <typeparam name="T">The type of asset this factory can create.</typeparam>
public class DefaultAssetFactory<T> : AssetFactory<T> where T : Asset
{
public static T Create()
{
return Activator.CreateInstance<T>()!;
}
/// <inheritdoc/>
public override T New()
{
if (typeof(T).GetConstructor(Type.EmptyTypes) == null)
throw new InvalidOperationException("The associated asset type does not have a public parameterless constructor.");
return Create();
}
}
View on GitHub (pinned to 96fad776d2)