Search code examples
.netsitecoresitecore7

Sitecore Include Files sort order broken


Suddenly, Lucene indexes at my Sitecore website got broken and after some investigation, I've noticed that Sitecore include files are "patching" web.config in non-alphabetical order.

John West mentioned in one of hist blog posts:

Sitecore processes Web.config include files in alphabetical order (technically, the order returned by the Directory.GetFiles() method).

However, MSDN says:

The order of the returned file names (from GetFiles()) is not guaranteed; use the Sort() method if a specific sort order is required.

What could cause that kind of issues? Is it something related to the server configuration?


Solution

  • I have a trick that you can use if you need to ensure that your own config include is always included after all the other include files.
    Make sure all the default and vendor .config files are located directly in the /App_Config/Include folder and then create one sub folder in which you place your own include file, for example /App_Config/Include/Custom/MyConfig.config.

    This way your config include is always loaded last because files from the top-level folder are always returned first by the Directory.GetFiles() method.