Wednesday, June 22, 2011

Copy Pasting Config files under App_Config cause the website to throw Null Ref Exception

Server Error in '/' Application.
________________________________________
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.

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:

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

[TypeInitializationException: The type initializer for 'Sitecore.Diagnostics.LoggerFactory' threw an exception.]
Sitecore.Diagnostics.Log.Error(String message, Exception exception, Type ownerType) +84
Sitecore.Diagnostics.Log.Error(String message, Type ownerType) +45
Sitecore.Configuration.Factory.LoadAutoIncludeFiles(ConfigPatcher patcher, String folder) +682
Sitecore.Configuration.Factory.LoadAutoIncludeFiles(XmlNode element) +77
Sitecore.Configuration.Factory.GetConfiguration() +230
Sitecore.Configuration.Factory.GetConfigNode(String xpath, Boolean assert) +86
Sitecore.Configuration.Factory.GetConfigNode(String xpath) +29
Sitecore.Resources.Media.UploadWatcher.InitializeIgnoreList() +100
Sitecore.Resources.Media.UploadWatcher..cctor() +51

[TypeInitializationException: The type initializer for 'Sitecore.Resources.Media.UploadWatcher' threw an exception.]

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
System.Web.Configuration.Common.ModulesEntry.Create() +39
System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +156
System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1219
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +97
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +188
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +295
System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr appContext, HttpContext context) +56
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +231

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


Just today as part of config files sync, I have migrated config files across environment, however after I have migrated config by means of copy pasting the file (i.e. rather than opening up editor and copy pasting content). it cause the website to go down. The error is as shown below.

I have tried to
1. Restoring the backup config files (i thought the config files that cause this issue) That doesnt fix it.
2. Restart IIS
3. Restart apppool
4. Reassigning security settings

All of the above doesnt work. So i decided to create brand new IIS Instance and point the physical path to the webroot (with the config changes implemented).

it works!! I conclude somehow the IIS/Apppool must have gone crazy A.K.A corrupted.

However there are times we have implemented lots of setting to the IIS Instance (e.g. whitelisted IPs, SSL certificate, header expiry). it will be a pain to set this up again. Luckily i didnt just delete the old IIS instance. So I try to narrow down the cause of the issue, i try to point the old IIS instance Apppool to the newly created APPPool, and viola it also works! So now i know something must have gone wrong in APPPool. I try to play around with the old APPPool, but in the end i recreate the APPPool with the same name and now it works just like per normal.

1 comment: