Calling .ConfigureCmsDefaults() makes initialization to skip Configure(IApplicationBuilder app, IWebHostEnvironment env)



I'm trying to upgrade a CMS site and when using .ConfigureCmsDefaults() in Program.cs

return Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration(config =>
                    config.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("COMPUTERNAME")}.json", optional: true, reloadOnChange: true);
                .ConfigureWebHostDefaults(webBuilder =>

the method:

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

is not called in Startup.cs.

If I remove .ConfigureCmsDefaults() the method get called.

Any ideas?


Jan 18, 2022 8:17

Hi Kristoffer

Unfortunately, I can't replicate the issue. Would you mind sharing full source of your program and startup? Alternatively, you can see my test recording from here to compare with your one. 

Edited, Jan 19, 2022 7:48


I just figured it out.
I my old solution I was using |DataDirectory| do attach a local database so my connectionstring looked like this:

"EPiServerDB": "Data Source=(LocalDb)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\EPiServerDB_f6c7a112.mdf;Initial Catalog=EPiServerDB_f6c7a112;Connection Timeout=60;Integrated Security=True;MultipleActiveResultSets=True"

To be able to use |DataDirectory| I found some where that you could do this in your Configure:

string baseDir = env.ContentRootPath;
AppDomain.CurrentDomain.SetData("DataDirectory", System.IO.Path.Combine(baseDir, "App_Data"));

It looks like ConfigureCmsDefaults() tries to connect to the database using the current connectionstring and that one is not modified yet.
So I guess there is some kind of exception in ConfigureCmsDefaults() that is not shown that causes the startup to break.

Changing |DataDirectory| to the actuall path to the database made the startup to work correctly.


Edited, Jan 19, 2022 8:30

Glad to hear you find the root cause and thanks for sharing your findings :) 

Jan 19, 2022 22:30
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.