Try our conversational search powered by Generative AI!

.NET 6 new (minimal) hosting model with CMS 12 giving exception at startup



I'm trying to use the new minimal hosting model that was introduced in .NET 6 but I'm stumbling against an error that I'm unsure of how to resolve. the app runs fine on the old hosting model with .NET 6, so this isn't a blocker, but it would be nice though.

The exeption I'm getting at startup is:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at EPiServer.Shell.Modules.ModuleInitializer.RegisterNlsRoute(String name, String path, ShellModule shellModuleNamedShell, ShellModule module, String clientResourcePath, IEndpointRouteBuilder routeBuilder)
at EPiServer.Shell.Modules.ModuleInitializer.RegisterClientResourceRoutes(IEnumerable`1 modules, IEndpointRouteBuilder routeBuilder)
at EPiServer.Shell.Routing.ShellEndpointRoutingExtension.InitializeModules(IEndpointRouteBuilder routeBuilder, IEnumerable`1 modules)
at EPiServer.Shell.Routing.ShellEndpointRoutingExtension.MapEndpoints(IEndpointRouteBuilder endpointRouteBuilder)
at EPiServer.Web.Routing.EndpointRouteBuilderExtensions.MapEPiServerExtensionEndpoints(IEndpointRouteBuilder defaultEndpointRouteBuilder)
at EPiServer.Web.Routing.ContentEndpointRouteBuilderExtensions.MapContent(IEndpointRouteBuilder defaultEndpointRouteBuilder)
at Web.Startup.<>c__DisplayClass3_0.<Configure>b__0(IEndpointRouteBuilder endpoints) in C:\Dev\Experiments\Web\Startup.cs:line 311
at Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder builder, Action`1 configure)
at Web.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Dev\Experiments\Web\Startup.cs:line 309
at Program.<Main>$(String[] args) in C:\Dev\Experiments\Web\Program.cs:line 19

The Program.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Web;

// New hosting model (not starting)

var builder = WebApplication.CreateBuilder(args);


var configuration = builder.Configuration;
var environment = builder.Environment;

var startup = new Startup(configuration);


var app = builder.Build();

startup.Configure(app, environment);


// Old hosting model (starting)

var builder = Host.CreateDefaultBuilder(args);


builder.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());

var app = builder.Build();


Is the new hosting model supported by CMS 12 yet or am I missing something?

May 16, 2022 15:28

If I remember rightly it's not supported yet due to some internal complexities of Optimizely on the ordering of how things run. Same goes for minimal APIs, I beleve they are working on an update.

May 17, 2022 9:15

Unfortunately we do not support the new hosting model yet. We have to introduce breaking changes to our initialization to make it work, that's why we decided to wait.

May 17, 2022 15:49

I guess this is on the feature list for CMS 13? Do you have a roadmap for future CMS versions? 

Nov 09, 2022 8:46

We have this but we haven't planned for a new major version yet, to my knowledge. 

Nov 09, 2022 12:37

What kind of breaking change are you looking at if you don't mind me asking?

Nov 09, 2022 19:11
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.