OrchardCMS/OrchardCore · error · InvalidOperationException

Unable to find view ' '. The following locations were…

Error message

Unable to find view '{viewName}'. The following locations were searched:

What it means

When the underlying view engine cannot locate the Razor view for a shape template, RazorShapeTemplateViewEngine aggregates every searched location into one message and throws InvalidOperationException. The shape's template view simply does not exist in any of the module/theme view locations searched.

Solutions

  1. Create the missing view at one of the listed searched locations (examine the error message paths)
  2. Fix the shape type/template name or alternate naming to match an existing .cshtml
  3. Ensure the .cshtml is included in the module project (RazorSdk compiles it) and the module is enabled
  4. If overriding in a theme, place the override at the exact convention path the engine searches

Example fix

// before
// shape type: MyWidget, but only Views/MyWidgety.cshtml exists
// after
// add src/My.Module/Views/MyWidget.cshtml so FindView resolves it
Defensive patterns

Strategy: fallback

Try / catch

try { html = await displayManager.RenderAsync(shape); } catch (InvalidOperationException e) when (e.Message.StartsWith("Unable to find view")) { _logger.LogError(e, "Shape template missing"); html = HtmlString.Empty; }

Prevention

When it happens

Trigger: Rendering a shape whose template view name (from the shape type, template alternates, or ShapeTemplateViewEngine conventions) matches no .cshtml file in any active module or theme; missing view compiled into the module assembly.

Common situations: Typo in shape type or template name; template .cshtml not added as embedded/compiled Razor view; alternates pointing to a template that was renamed; view placed in wrong folder path (Views/Items-foo.cshtml conventions); theme override missing after switching themes.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/292f2e70376566ec. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.DisplayManagement/Razor/RazorShapeTemplateViewEngine.cs:139

    {
        var getViewResult = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true);
        if (getViewResult.Success)
        {
            return getViewResult.View;
        }

        var findViewResult = viewEngine.FindView(actionContext, viewName, isMainPage: true);
        if (findViewResult.Success)
        {
            return findViewResult.View;
        }

        var searchedLocations = getViewResult.SearchedLocations.Concat(findViewResult.SearchedLocations);
        var errorMessage = string.Join(
            System.Environment.NewLine,
            new[] { $"Unable to find view '{viewName}'. The following locations were searched:" }.Concat(searchedLocations));

        throw new InvalidOperationException(errorMessage);
    }

    private IHtmlHelper MakeHtmlHelper(ViewContext viewContext, ViewDataDictionary viewData)
    {
        if (_htmlHelper is IViewContextAware contextAwareHelper)
        {
            var newViewContext = new ViewContext(viewContext, viewContext.View, viewData, viewContext.Writer);
            contextAwareHelper.Contextualize(newViewContext);
        }

        return _htmlHelper;
    }
}

View on GitHub (pinned to 4306c0717f)