From 220414114e51ad2ce63bbb256ce3bf234d756b9f Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 7 Mar 2023 11:21:57 +0100 Subject: [PATCH] Fallback to use ActivatorUtilities to create controller from type, if it is not registered in DI (#13910) --- src/Umbraco.Web.Common/Routing/UmbracoVirtualPageRoute.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.Common/Routing/UmbracoVirtualPageRoute.cs b/src/Umbraco.Web.Common/Routing/UmbracoVirtualPageRoute.cs index f0d0427438..cff5a589f6 100644 --- a/src/Umbraco.Web.Common/Routing/UmbracoVirtualPageRoute.cs +++ b/src/Umbraco.Web.Common/Routing/UmbracoVirtualPageRoute.cs @@ -61,8 +61,9 @@ public class UmbracoVirtualPageRoute : IUmbracoVirtualPageRoute if (controllerType != null) { - // Get the controller for the endpoint - var controller = httpContext.RequestServices.GetRequiredService(controllerType); + // Get the controller for the endpoint. We need to fallback to ActivatorUtilities if the controller is not registered in DI. + var controller = httpContext.RequestServices.GetService(controllerType) + ?? ActivatorUtilities.CreateInstance(httpContext.RequestServices, controllerType); // Try and find the content if this is a virtual page IPublishedContent? publishedContent = FindContent(