When Application_End isn't called in asp.net WebService
.net, application-end, asp.net, c#, iis
Solution
It seems that the brutal shut down can be caused by OutOfMemoryException that caused failure in creating AppDomain that are needed for executing requests. In this scenario Application_end won't be called.
Event Type: Error Event Source: ASP.NET 2.0.50727.0 Event Category: None Event ID: 1334 Date: 4/22/2012 Time: 11:23:13 AM User: N/A Computer: CCBSHAIS02 Description: Failed to initialize the AppDomain:/LM/W3SVC/1/Root/AgentWS
Exception: System.SystemException
Message: Failed to create AppDomain.
StackTrace: at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters) at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)
InnerException: System.OutOfMemoryException
Message: Exception of type 'System.OutOfMemoryException' was thrown.
StackTrace: at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor) at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info) at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)
for further reading on IIS and AppDomains look at: http://weblogs.asp.net/owscott/archive/2007/09/02/application-vs-appdomain.aspx
Problem
I know that in the following cases Apllication_end will be called: - edit the config file for an application that's running. - change a dll in the bin directory. - stop (or restart) IIS. - Process Recycling turned on either in IIS6 App Pools, or using the aspnet worker process. but my question is what are the cases when it's won't be called? I know it won't be called if you manually End w3wp process or if the server will brutally shut down. Is there any other scenarios? Thanks!