Skip to content
October 29, 2013 / kiranpatils

The type initializer for ‘Sitecore.Diagnostics.LoggerFactory’ threw an exception

Challenge:

My dear readers, How are you? Apologize for being away since so long. Was busy with few things [Yes, Yes, Whenever you find me busy. After that will have loads of learnings to share with you!]. And yes, you must’ve seen my earlier blog post on updating your Sitecore knowledge daily/weekly

Let’s start, Before few weeks back. We were migrating our Websites from .NET 2.0 App Pool to .NET 4.0, And while doing that we faced strange error on only one server, The error looks like following:

[NullReferenceException: Object reference not set to an instance of an object.]
Sitecore.Diagnostics.Log.Error(String message, Exception exception, Type ownerType) +133
Sitecore.Diagnostics.Log.Error(String message, Type ownerType) +45
Sitecore.Configuration.Factory.LoadAutoIncludeFiles(ConfigPatcher patcher, String folder) +680
Sitecore.Configuration.Factory.LoadAutoIncludeFiles(XmlNode element) +63
Sitecore.Configuration.Factory.GetConfiguration() +347
Sitecore.Diagnostics.LoggerFactory..cctor() +67

[TypeInitializationException: The type initializer for ‘Sitecore.Diagnostics.LoggerFactory’ threw an exception.]
Sitecore.Diagnostics.LoggerFactory.GetLogger(Type type) +17
Sitecore.Diagnostics.Log.Error(String message, Exception exception, Type ownerType) +93
Sitecore.Diagnostics.Log.Error(String message, Type ownerType) +45
   Sitecore.Configuration.Factory.LoadAutoIncludeFiles(ConfigPatcher patcher, String folder) +680
   Sitecore.Configuration.Factory.LoadAutoIncludeFiles(XmlNode element) +63
Sitecore.Configuration.Factory.GetConfiguration() +347
Sitecore.Configuration.Factory.GetConfigNode(String xpath, Boolean assert) +82
Sitecore.Configuration.Factory.GetConfigNode(String xpath) +29
Sitecore.Resources.Media.UploadWatcher.InitializeIgnoreList() +114
Sitecore.Resources.Media.UploadWatcher..cctor() +51

[TypeInitializationException: The type initializer for ‘Sitecore.Resources.Media.UploadWatcher’ threw an exception.]
Sitecore.Resources.Media.UploadWatcher..ctor() +0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1136
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +23
System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +60
System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +231
System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1365
Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleReflectionUtil.GetIntegratedModuleCollection(HttpApplication target, IntPtr appContext) +33
Microsoft.Web.Infrastructure.DynamicModuleHelper.CriticalStatics.Init(HttpApplication context) +179
Microsoft.Web.Infrastructure.DynamicModuleHelper.IntegratedDynamicModule.Init(HttpApplication context) +6
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +517
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9087676
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

We Investigated lot of time to figure out, Why this error? And this was coming up in start-up of Sitecore only.  What, You are also facing the same error? Searching for a solution? Then you are at the right post, We’ve a solution for you!

Solution:

After Investing 5+ hours, We finally found a solution. Here are the steps which we did:

  1. Did a quick search and found following links:
    1. http://stackoverflow.com/questions/9587257/tracking-nullreferenceexceptions-in-sitecore — Gone through initial post. But was not much helpful
    2. http://techblog.lbigroup.be/2012/08/13/nullreferenceexception-uploadwatcher/ — Was not for me, As it has something to do with SlowCheetah, Whichh we don’t use — Is it for you?
    3. http://maesitus-sitecore.blogspot.in/2011/06/copy-pasting-config-files-under.html — Suggests to play around with App Pool. Tried it. But with no luck 😦 — Even though you can give a go!
  2. Then we read error closely, and this line [ Sitecore.Configuration.Factory.LoadAutoIncludeFiles(XmlNode element)] gave us an idea to replace all our App_Config/Include folder from WORKING box to Not Working BOX. And it worked! Then we checked what was the issue in old files [Yeah, we backed up before replacing them!] and we found that one Config file was not well-formed!

Simple? Hope this helps!

Good reads!

http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/05/All-About-Web-config-Include-Files-with-the-Sitecore-ASPNET-CMS.aspx

http://briancaos.wordpress.com/2010/09/23/sitecore-web-config-include-files-auto-include/

Happy Auto Including! 🙂

Advertisements

3 Comments

Leave a Comment
  1. andrewwhitten / May 21 2014 8:12 am

    Thanks! I think you just saved me 5 hours as well 🙂

    • kiranpatils / Jun 2 2014 11:34 am

      Glad to know that! 🙂

  2. Nona Durham / Jul 2 2014 2:50 am

    I was about an hour into researching this one! Phewww. We do use slowcheetah, the issue I had were the transforms were in the include directory. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: