Loading...

Importance of making sure that correct xmlns:patch attribute is in included Sitecore config files

So, recently I ran into a bit of a problem with a custom pipeline in one of the Sitecore projects I've been working on. NotFound404Processor custom pipeline was not setting Sitecore Context correctly and Context.Database was always set to null. This was kind of weird since this particular pipeline used to work just fine and then it just stopped working. After little bit of troubleshooting I noticed that one of the developers changed the xmlns:patch attribute in the included config file and this was the root of my problem.

You can read more about Web.config Include Files with the Sitecore CMS here.

Here is the config file with the incorrect xmlns:patch. You can see that developer changed it to http://local.sitecore.net/xmlconfig


<?xml version="1.0"?>
<configuration xmlns:patch="http://local.sitecore.net/xmlconfig" xmlns:set="http://local.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <httpRequestBegin>
        <processor patch:after="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"
                   type="ProjectName.Website.Pipelines.Http.NotFound404Processor, ProjectName.Website" />
      </httpRequestBegin>
    </pipelines>
  </sitecore>
</configuration>

You can see that xmlns:patch="http://local.sitecore.net/xmlconfig" and xmlns:set="http://local.sitecore.net/xmlconfig/set/". This is incorrect and when that is in your config this is what happens when you debug the pipeline. Take a look at the screenshot below.

 

If you go to /sitecore/admin/showconfig.aspx you can see NotFound404Processor entry is kind of a mess.

To fix this all that was needed was to make sure that xmlns:patch attribute was set to http://www.sitecore.net/xmlconfig like in the code snip below.


<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <httpRequestBegin>
        <processor patch:after="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"
                   type="ProjectName.Website.Pipelines.Http.NotFound404Processor, ProjectName.Website" />
      </httpRequestBegin>
    </pipelines>
  </sitecore>
</configuration>

Now, if you go to /sitecore/admin/showconfig.aspx you can see we are all good ;)

That's it for today. Hopefully this can help someone.

Disclaimer
This is a personal blog. The opinions expressed here represent my own and not those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.. In addition, my thoughts and opinions change from time to time I consider this a necessary consequence of having an open mind. This blog disclaimer is subject to change at anytime without notifications.