7

The CD version of Sitecore 9 was installed on our CD server. The error below is typically seen with a SwitchMasterToWeb.config file issue in previous versions:

Post condition failed Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:

System.InvalidOperationException: Post condition failed

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Post condition failed]
Sitecore.Diagnostics.Assert.ResultNotNull(T result, String message) +85 Sitecore.Configuration.DefaultFactory.GetDatabase(String name) +86 Sitecore.Configuration.DefaultFactory.GetDatabases() +121 Sitecore.Data.Managers.DefaultItemManager.Initialize() +110 (Object , Object[] ) +120 Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +479 (Object , Object[] ) +71
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +479
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
Sitecore.Nexus.Web.HttpModule.Application_Start() +161
Sitecore.Nexus.Web.HttpModule.Init(HttpApplication app) +767
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +583
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +169
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +396
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +333

[HttpException (0x80004005): Post condition failed]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +525
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +124 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +700

In this case, with Sitecore 9 we are getting this error with the CD version. Configuration role for CM is set to "ContentManagement" with CD being "ContentDelivery".

To my understanding, this is all you need to do to have your CD instance all setup since there is no longer a SwitchMasterToWeb.config in Sitecore 9.

Am I missing something? Any ideas or anyone seen this before on a CD instance with Sitecore 9?

4
  • Did you get chance to have a look at this blog post from jammykam on configuring roles on Sitecore 9 ? jammykam.wordpress.com/2017/10/17/rules-based-configuration Commented Jan 16, 2018 at 20:34
  • I did. Looked through and that's how I made my change to "ContentManagement" and "ContentDelivery" for the roles from "Standalone". Again, I believe that is all that is needed, but no-go for now. Commented Jan 16, 2018 at 21:40
  • @TobyGutierrez if this question is now answered, can you mark the answer please?
    – Richard Seal
    Commented May 10, 2018 at 14:30
  • I want to also note that this is a very ambiguous error. This can happen if the configuration of the core db is missing in the Sitecore.config. This happened to us when our transforms went haywire. it was not an easy thing to track down. Commented Jun 26, 2018 at 22:41

6 Answers 6

3

Obviously, the cause of this error is diverse.

The error message appears when configuration define a database that is not configured or available in the environment.

I had this issue with Sitecore module UrlRewrite. Please make sure that:

Hi.UrlRewrite.Prefetch.Master.config

is disabled in CD enviroment.

2
  • And that was exactly the case with my deployment when adding the UrlRewrite module. I noticed the configs were not installed on my CDs and I copied them there. Once I disabled that one, happiness ensued. Thanks so much for that answer! Commented Feb 24, 2020 at 22:40
  • I forget to change <add key="role:define" value="Standalone" /> after my testing is done. Commented Aug 27, 2020 at 4:43
2

In my case, I had the same error when I delivered Unicorn configs to CD server. I removed all Unicorn configs from CD and added Unicorn folder with configs to my pubxml:

<Target Name="ConfigFiles" BeforeTargets="ExcludeFilesFromPackage">
    <ItemGroup>
      <ExcludeFromPackageFolders Include="App_Config\Include\Unicorn">
        <FromTarget>Project</FromTarget>
      </ExcludeFromPackageFolders>
      <ExcludeFromPackageFiles Include="App_Config\Include\*.disabled">
      </ExcludeFromPackageFiles>
      <ExcludeFromPackageFiles Include="App_Config\Include\*.example">
      </ExcludeFromPackageFiles>
      <ExcludeFromPackageFiles Include="App_Config\Include\*.exclude">
      </ExcludeFromPackageFiles>
    </ItemGroup>
  </Target>
0

I solved this issue by redeploying my latest code with "ContentManagement" in place for the CM server configuration role and "ContentDelivery" in place for the CD server configuration role. When the deploy finished as successful it was only then that everything started working. Apparently, simply modifying in the Web.configs, via patch file of course, and doing a recycle did not do the trick for me. Happy coding!

2
  • Well, you can't patch the Web.config file and thereby the app settings, so that might have been why :) Commented Jan 17, 2018 at 7:46
  • My apologies. I meant a .config transform via Slow Cheetah. Commented Jan 17, 2018 at 12:44
0

In my case, I solved it by removing the Unicorn.DataProvider.config file from the CD environment. This config file contains the following section:

<sitecore>
  <databases>
      <database id="master">

... which causes Sitecore to look for a master database, which in turn causes the exception.

2
  • 1
    As stated in Unicorn.DataProvider.config; This file should be removed in ANY deployed instance (CE or CD) that does not act as a source for serialized item updates.
    – Mark Cassidy
    Commented Nov 20, 2018 at 13:56
  • Thanks Andres it worked for me Commented Jul 23, 2019 at 21:24
0

In my case I fixed the issue on our CD server by running the following Script in powershell after having running unicorn sync.

Remove-Item -Path "$WebsiteDir\$WebsiteDir\App_Config\Include\Unicorn" -Force -Recurse -Verbose

Apparently leaving it on the CMS server works, but not the CD.

0

Sitecore removed core db references from v9.1. If there is a reference of core db in a custom configuration, Sitecore will throw "Post condition failed" exception.

In order to fix it, core db reference needs to be removed from the custom configuration. One place where core database may be used in Sitecore 9 and below is .

http://www.nehemiahj.com/2021/06/sitecore-post-condition-failed.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.