November Happy Hour will be moved to Thursday December 5th.

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

Vote:
 

Hi!

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);
                })
                .ConfigureCmsDefaults()
                .UseSerilog()
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

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?

/Kristoffer

#270158
Jan 18, 2022 8:17
Vote:
 

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 https://www.youtube.com/watch?v=KzjKMr3NsgQ to compare with your one. 

#270210
Edited, Jan 19, 2022 7:48
Vote:
 

Hi!

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.

/Kristoffer

#270211
Edited, Jan 19, 2022 8:30
Vote:
 

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

#270227
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.