2

I've recently upgraded a

  • Sitecore 7.2 (rev. 140526) with Webforms for Marketers 2.4 (rev. 141008)

to

  • Sitecore 8.2, Update 1 (rev. 161115) with Webforms for Marketers 8.2 (rev. 161129)

I have a single server setup, with no CD servers. Everything is done on the same server. No analytics or tracking enabled. I use a pure SQL setup without any Mongo database.

For the most part, it has been working well, but periodically I get the following error when I try to log into Sitecore:

Server Error in '/' Application.

contextDatabase

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: contextDatabase

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: contextDatabase]
   Sitecore.Forms.Core.Dependencies.DefaultImplItemRepository..ctor(Database contextDatabase, Database masterDatabase) +103

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +438
   Sitecore.Reflection.ReflectionUtil.CreateObject(Type type, Object[] parameters) +119
   Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert) +117
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +163
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert) +72
   Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert) +615
   Sitecore.Configuration.DefaultFactory.CreateFromReference(XmlNode configNode, String[] parameters, Boolean assert) +170
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +116
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert) +72
   Sitecore.Configuration.DefaultFactory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert) +109
   Sitecore.Configuration.DefaultFactory.GetConstructorParameters(XmlNode configNode, String[] parameters, Boolean assert) +161
   Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert) +103
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +163
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert) +72
   Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert) +615
   Sitecore.Configuration.DefaultFactory.CreateFromReference(XmlNode configNode, String[] parameters, Boolean assert) +170
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +116
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert) +72
   Sitecore.Configuration.DefaultFactory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert) +109
   Sitecore.Configuration.DefaultFactory.GetConstructorParameters(XmlNode configNode, String[] parameters, Boolean assert) +161
   Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert) +103
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +163
   Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, Boolean assert) +68
   Sitecore.Events.EventSubscribers.Add(String eventName, XmlNode configNode) +545
   Sitecore.Events.Event.GetConfigSubscribers() +562
   Sitecore.Events.Event.RaiseEvent(String eventName, Object[] parameters) +373
   Sitecore.Data.DataProviders.Sql.SqlDataProvider.SetProperty(String parameterName, String value, CallContext context) +274
   Sitecore.Data.DataProviders.DataProvider.SetProperty(String name, String value, CallContext context, DataProviderCollection providers) +124
   Sitecore.Data.DataManager.SetProperty(String name, String value) +116
   Sitecore.Web.Authentication.DefaultTicketManager.CreateTicket(String userName, String startUrl, Boolean persist) +436
   Sitecore.Pipelines.LoggedIn.Ticket.Process(LoggedInArgs args) +57

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +128
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +146
   Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj) +89
   Sitecore.Nexus.Pipelines.NexusPipelineApi.Resume(PipelineArgs args, Pipeline pipeline) +313
   Sitecore.Pipelines.Pipeline.Start(PipelineArgs args, Boolean atomic) +173
   Sitecore.Pipelines.Pipeline.Start(String pipelineName, PipelineArgs args, Boolean atomic) +89
   Sitecore.sitecore.login.Default.LoggedIn() +134
   Sitecore.sitecore.login.Default.LoginClicked(Object sender, EventArgs e) +76
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11773413
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150
   System.Web.UI.<ProcessRequestMainAsync>d__523.MoveNext() +8499

It appears to be an issue with WFFM's item repository. To further investigate I've done the following:

  • I've checked the code that provides the context database (StaticSettings.ContextDatabase) and not matter when I call it during my pipeline it returns the database and not null.
  • I've tried to create my own instance of DefaultImplItemRepository and it also works fine.

Sometimes the error goes away by itself. I do stuff like restart the browser, clear the cache, clear the cookies, restart the IIS, the website or the application pool, log into sitecore using incognito, or open the console and disable caching.

After the error is gone it will normally be gone for the rest of the day. But once it comes back it can take hours before it "leaves".

Any help is welcome as I am pulling my hair out of my head, trying to fix this


UPDATE 1

After looking into the Sitecore logs I've found the following error thrown. It starts of differently but then has the other 3 nested exceptions with in it. The entire error from the logs can be seen here:

30592 11:27:13 ERROR Application error.
Exception: System.Web.HttpUnhandledException
Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Source: System.Web
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.<ProcessRequestMainAsync>d__523.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Util.WithinCancellableCallbackTaskAwaitable.WithinCancellableCallbackTaskAwaiter.GetResult()
   at System.Web.UI.Page.<ProcessRequestAsync>d__515.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.UI.Page.<ProcessRequestAsync>d__554.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar)
   at ASP.sitecore_login_default_aspx.EndProcessRequest(IAsyncResult ar) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\ef3f15d9\94a73b47\App_Web_cfepw0f1.0.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Nested Exception

Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj)
   at Sitecore.Nexus.Pipelines.NexusPipelineApi.Resume(PipelineArgs args, Pipeline pipeline)
   at Sitecore.Pipelines.Pipeline.Start(PipelineArgs args, Boolean atomic)
   at Sitecore.Pipelines.Pipeline.Start(String pipelineName, PipelineArgs args, Boolean atomic)
   at Sitecore.sitecore.login.Default.LoggedIn()
   at Sitecore.sitecore.login.Default.LoginClicked(Object sender, EventArgs e)
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.<ProcessRequestMainAsync>d__523.MoveNext()

Nested Exception

Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Sitecore.Reflection.ReflectionUtil.CreateObject(Type type, Object[] parameters)
   at Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateFromReference(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.GetConstructorParameters(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateFromReference(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.GetConstructorParameters(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
   at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, Boolean assert)
   at Sitecore.Events.Event.EventSubscribers.Add(String eventName, XmlNode configNode)
   at Sitecore.Events.Event.GetConfigSubscribers()
   at Sitecore.Events.Event.RaiseEvent(String eventName, Object[] parameters)
   at Sitecore.Data.DataProviders.Sql.SqlDataProvider.SetProperty(String parameterName, String value, CallContext context)
   at Sitecore.Data.DataProviders.DataProvider.SetProperty(String name, String value, CallContext context, DataProviderCollection providers)
   at Sitecore.Data.DataManager.SetProperty(String name, String value)
   at Sitecore.Web.Authentication.DefaultTicketManager.CreateTicket(String userName, String startUrl, Boolean persist)
   at Sitecore.Pipelines.LoggedIn.Ticket.Process(LoggedInArgs args)

Nested Exception

Exception: System.InvalidOperationException
Message: contextDatabase
Source: Sitecore.Forms.Core
   at Sitecore.Forms.Core.Dependencies.DefaultImplItemRepository..ctor(Database contextDatabase, Database masterDatabase)

I am still clueless to what can cause this error. Any help is welcome


Update 2

Something that temporarily remove the error was upgrading our old MongoDB.

Our server was running MongoDB 2.6.3. My local machine is running MongoDB 3.2.13

Whenever I tried to access my local mongo everything would work. Updating the server's mongoDB to 3.0.15-10-g056b343 removed the issue temporarily.


UPDATE 3

The Mongo upgrade did not fix the issue. Another workaround has been found. Adding the following to the url, should allow login:

?sc_content=master

So if you try to login at your site at www.mysite.com/sitecore/login, add the above query to the url, reload the site and then login agian

www.mysite.com/sitecore/login?sc_content=master

This works because sitecore makes a lookup for the content database on login and adding this allows it to find the master database instead of null.

See this code snippet for more information:

namespace Sitecore
{ 
    /// <summary>Gets the current content database.</summary>
    /// <value>The content database.</value>
    /// <remarks>
    ///     <para>This property specifies which database is being edited by the client. Usually
    /// this is the Master database.</para>
    ///     <para>Normally this property is only accessed from within the client.</para>
    ///     <para>The value is specified in the Sites section in the web.config.</para>
    /// </remarks>
    public static Database ContentDatabase
    {
      get
      {
        Database database = Context.Items["sc_ContentDatabase"] as Database;
        if (database == null)
        {
          string name = WebUtil.GetQueryString("sc_content");
          if (name.Length == 0)
            name = Sitecore.Configuration.State.ContentDatabase;
          SiteContext site = Context.Site;
          if (site != null)
          {
            string property = site.Properties["content"];
            if (name.Length == 0)
              name = property;
          }
          if (string.IsNullOrEmpty(name))
            return (Database) null;
          database = Factory.GetDatabase(name, false);
          Assert.IsNotNull((object) database, "Content database '" + name + "' not found.");
          Assert.IsTrue(!database.Protected || Context.IsAdministrator, "Content database '" + name + "' requires administrative priviliges.");
          Context.Items["sc_ContentDatabase"] = (object) database;
        }
        return database;
      }
    }

Update 4

Further investigation, using decompiled assemblies of Sitecore.Forms.Core and Sitecore.Kernel reveals that a WFFM evnet is fired during login. At the line

Sitecore.Events.EventSubscribers.Add(String eventName, XmlNode configNode) +545

The variable eventName has the value wffm:action:remote. So for some reason this event is fired at login, which triggers WFFM to get the context database, which again fails

  • 1
    Have you checked the Sitecore logs? There may be a relevant error before or after the yellow screen – Ben Lipson Sep 6 '17 at 13:38
  • I have now. It doesn't add much information though, but maybe someone can more information from it – Black_bull Sep 7 '17 at 9:33
  • 1
    This error occurs when there's a mismatch between WFFM and Sitecore versions. While the ones you list are a match; are you absolutely sure there are not residual Sitecore 7.x DLLs still floating about? Can easily happen during upgrades; where your obj/ folders etc still hold 7.x assemblies when compiling project. Check your Sitecore.Kernel.DLL – Mark Cassidy Sep 7 '17 at 21:11
  • @MarkCassidy Thank you for your attention. I have deleted my bin/obj folders multiple times. I've just searched through every single .dll file in the bin folder, and every single file matches with my clean Sitecore 8.2 install. Only the SolrNet dll had a small miss match, which I solved. This did not resolve the issue. I've also checked every single reference in my code to external .dll files and every reference points to the new files. Sitecore.Kernel is correct and have been for a long time. I've previously been able to login without a problem. – Black_bull Sep 8 '17 at 11:53
  • 1
    @Black_bull: How about indexes, are you able to rebuild indexes and try?. Can you check if any Lucene references still exist? – Siva Sankar Sep 11 '17 at 8:59
2

The solution to the answer as in the Sitecore event handler pipeline.

Our project had a custom event that initialized a constructor that threw and exception. This made the entire event pipeline fail, and thus require it to be rebuild. Rebuilding the event pipeline during login made WFFM throw an error.

The code in question was this:

<sitecore>
    <events>
      <event name="publish:end" xdt:Locator="Match(name)">
        <handler type="SCommerce.Scheduling.Administration.Logic.SitecoreQuartzTriggerUpdater, SCommerce.Scheduling.Administration" method="RefreshTriggers" xdt:Transform="Insert"/>
      </event>
    </events>
</sitecore>

I was only able to solve this issue with the help from the Sitecore support team. To read more see the entire thread here: https://support.sitecore.net/helpdesk/viewitem?id=492421&type=defects&force_use_number=false

and to get the final answer from Sitecore you can read it here:

I think I might know the culprit (atleast have some hunches). When an event occurs, Sitecore "pre-builds" all the required handlers which might be needed in future and saves them to Event.configSubscribers field. Judging by the stack trace you provided, this field must be null, or the chain of constructors would not have been launched. Thus, something prevents the collection from initializing. In the old logs you provided, the WFFM-related exception is surrounded by another event-related error:

at Sitecore.Events.Event.GetConfigSubscribers()
at Sitecore.Events.Event.RaiseEvent(String eventName, Object[] parameters)
at Sitecore.Jobs.Job.Start()
at Sitecore.Jobs.DefaultJobManager.RunJob(Job job)
at Sitecore.Jobs.DefaultJobManager.ProcessQueue()
at Sitecore.Jobs.DefaultJobManager.Start(JobOptions options)
at Sitecore.CES.DeviceDetection.Netbiscuits.DeviceDetectionClient.JobManagerWrapper.Start(JobOptions options)
at Sitecore.CES.DeviceDetection.Netbiscuits.DeviceDetectionClient.Tick()

Nested Exception

Exception: System.ArgumentNullException
Message: Value cannot be null.
Parameter name: httpContext
Source: SCommerce.Core
   at SCommerce.Core.Context.RequestContext..ctor(HttpContext httpContext) in D:\git\kamstrup-Sitecore8\src\SCommerce.Core\Context\RequestContext.cs:line 26
   at SCommerce.Core.Context.WebContext.get_Request() in D:\git\kamstrup-Sitecore8\src\SCommerce.Core\Context\WebContext.cs:line 41
   at SCommerce.Website.SCom.App_Code.ComponentsConfiguration.SchedulingConfiguration.GetSchedulingAdministrationConfiguration() in D:\git\kamstrup-Sitecore8\src\SCommerce.Website\SCom\App_Code\ComponentsConfiguration\SchedulingConfiguration.cs:line 10
   at SCommerce.Scheduling.Administration.Logic.SitecoreQuartzTriggerUpdater..ctor()

Perhaps, the failed initialization of other handler prevents the timely initialization of the whole configSubscribers collection. Could you please try to disable the "SCommerce.Scheduling.Administration.Logic.SitecoreQuartzTriggerUpdater" event handler and see if the issue can be reproduced again?

Also, I would like to clarify that the fix itself would be to get rid of ArgumentNullException in SCommerce.Core . Please re-check the code for SCommerce.Core.Context.RequestContext and make sure that the httpContext value in it is always initialized. This way, the relevant event handler will always be initialized and the login problems should not occur again. Let me know if the issue occurs even after the SCommerce event fix.

Best regards, Artem

| improve this answer | |
  • I am getting this exact error. I installed MongoDB v 3.2.1 per that compatibility chart, but the error persists. – raynjamin Sep 28 '17 at 11:08
  • @raynjamin When I tested my solution any form of cache gave me unreliable results. After every change I did the following to make sure the were absolutely no cache in action. * Kill the IIS w3wp process * Manually delete bin and object folder from my website project * Clean and Rebuild probject * Start up my site * When the site had started up, start up site.com/sitecore (if I did not wait for my site to start up, then the IoC might be initalized incorrectly, bringing back the error) * login again – Black_bull Sep 29 '17 at 12:19
  • @raynjamin could you give some more information about your setup? Is it single server? Is it running on a localmachine or a remote server? Have you turned off Analytics and xdb? Do you have a mongo server running on your solution (for non-sitecore data) or is it a pure sql setup? Are you sure your Sitecore and WFFM are compatible and there are no old sitecore files from before the upgrade (if it is an upgrade that you are doing)? – Black_bull Sep 29 '17 at 12:22
  • @raynjamin You are right. Today the error "returned" to my local enviroment and I am now again struggling to fix it. Have you made any progress on your project? – Black_bull Oct 5 '17 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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