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