OrchardCMS/OrchardCore · error · InvalidOperationException
Shape creation failed for type
Error message
Shape creation failed for type '{shapeType}'. The shape factory returned null. What it means
DefaultShapeFactory.CreateAsync fires Creating events, then invokes the registered internal creation logic (CreateInternalAsync). If that factory returns null — meaning no shape creation handler produced an instance for the type — it throws InvalidOperationException("Shape creation failed for type '{shapeType}'. The shape factory returned null.").
Solutions
- Check IShapeFactoryEvents.Creating implementations for the shape type — ensure they do not suppress or return without creating a shape.
- Verify the shape type is created via a known mechanism (dynamic proxy shape, typed shape class binding) and that related DI services are registered in Startup.
- Log the shapeType value and reproduce with a minimal call to isolate which handler nulls the result.
Example fix
// before (IShapeFactoryEvents)
public void Creating(ShapeCreatingContext context) { context.Cancel = true; }
// after
public void Creating(ShapeCreatingContext context) { /* allow default creation */ } Defensive patterns
Strategy: try-catch
Try / catch
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Shape creation failed"))
{
logger.LogError(ex, "Shape factory returned null for {Type}", shapeType);
return Results.NotFound();
} Prevention
- Never set Cancel/return null in IShapeFactoryEvents.Creating handlers
- Test custom shape types immediately after registering their creation services
- Avoid deriving shape types from unvalidated user input
When it happens
Trigger: Calling IShapeFactory.CreateAsync for a shape type whose internal creation pipeline (Creating handlers / default shape creation) returns null — e.g., a custom IShapeFactoryEvents or overriding CreateInternalAsync returning null, or a shape type with no valid creation path registered.
Common situations: Custom shape factory events that replace/intercept creation but forget to set a result; dynamic shape types created from user/config input where a handler bails out; broken DI registrations for shape creation services.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- The shape type ' ' is not found for the theme
- Fatal error, a Layout couldn't be created.
- DisplayAsync requires an instance of IShape
- Unable to find view ' '. The following locations were…
- DisplayAsync requires an instance of IShape
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/d820843f97b84057.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.DisplayManagement/Implementation/DefaultShapeFactory.cs:97
creating?.Invoke(creatingContext, state);
// 'Creating' events may add behaviors and alter base type.
foreach (var ev in _events)
{
ev.Creating(creatingContext);
}
if (shapeDescriptor != null)
{
foreach (var ev in shapeDescriptor.CreatingAsync)
{
await ev(creatingContext);
}
}
// Create the new instance.
var shape = await creatingContext.CreateInternalAsync()
?? throw new InvalidOperationException($"Shape creation failed for type '{shapeType}'. The shape factory returned null.");
var createdContext = new ShapeCreatedContext
{
ServiceProvider = _serviceProvider,
New = creatingContext.New,
ShapeFactory = creatingContext.ShapeFactory,
ShapeType = creatingContext.ShapeType,
Shape = shape,
};
var shapeMetadata = shape.Metadata;
shapeMetadata.Type = shapeType;
// Merge wrappers if there are any.
if (shapeDescriptor != null && shapeMetadata.Wrappers.Count + shapeDescriptor.Wrappers.Count > 0)
{
shapeMetadata.Wrappers.AddRange(shapeDescriptor.Wrappers);
}View on GitHub (pinned to 4306c0717f)