One ASP.NET application (randomly) in multiple application domains or frequent application reuse

I am debugging an ASP.NET application that seems to accidentally lose the contents of some static fields. I did some simple user logging (because even log4net was flaky), and found out that the application was loading into two application domains. Here is a snippet from the magazine:

6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 1 6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 2 6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 3 6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 4 6/27/2011 9:01:02 PM /LM/W3SVC/1/ROOT/MyApp-4-129537072620628334: log message 5 <- 6/27/2011 9:01:02 PM /LM/W3SVC/1/ROOT/MyApp-4-129537072620628334: log message 6 6/27/2011 9:04:50 PM /LM/W3SVC/1/ROOT/MyApp-1-129537074647228334: log message 7 6/27/2011 9:04:50 PM /LM/W3SVC/1/ROOT/MyApp-1-129537074647228334: log message 8 

The item after time / date is the current domain name of the application.

The application is a regular ASP.NET application (not MVC) that processes some AJAX request and passes them to a bunch of ASP.NET libraries. The only unusual thing is that one of the libraries uses a little reflection to search for some classes, which then instantiate and run them in separate threads. But it does nothing explicitly with application domains.

By the way, the highlighted line from the log file comes from the ASP.NET application itself (i.e. not from one of these separate threads) from the ASPX handler.

Am I interpreting the magazine correctly? If so, what can cause an application to be downloaded and serviced from multiple application domains?

Edit: This question is essentially related to this: ASP.NET application state and Static object . However, based on what I saw today, it is not possible to rely on static fields. I could move everything to the Application object, but I think synchronization will be a little cumbersome. I am becoming more and more convinced that the application is doing something non-standard.

Edit 2:. I have done a bit more research, and it seems that there is always a 1-1 relationship between application and application areas (which I expect). Therefore, I think that what I see is recycling.

Edit 3: After several experiments and rollovers, I turned on IIS health monitoring (based on http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session- variables-and-appdomain-recycles.aspx ), and found out that the application runs twice in quick succession. This is pretty unpleasant. The following are log events:

 Event code: 1003 Event message: Application compilation is starting. Event time: 6/28/2011 8:34:31 AM Event time (UTC): 6/28/2011 3:34:31 PM Event ID: d42336b18c264516a4ba5aa1e62df276 Event sequence: 1 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1/ROOT/MyApp-1-129537488697736549 Trust level: Full Application Virtual Path: /MyApp Application Path: [snip]\MyApp\ Machine name: US-SEA-R9759B2 Process information: Process ID: 7624 Process name: w3wp.exe Account name: IIS APPPOOL\DefaultAppPool ---- Event code: 1001 Event message: Application is starting. Event time: 6/28/2011 8:34:33 AM Event time (UTC): 6/28/2011 3:34:33 PM Event ID: f7fbecb1ba1a4a24833016cec47458c6 Event sequence: 1 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1/ROOT-2-129537488729428362 Trust level: Full Application Virtual Path: / Application Path: [snip]\RootApp\ Machine name: US-SEA-R9759B2 Process information: Process ID: 7624 Process name: w3wp.exe Account name: IIS APPPOOL\DefaultAppPool ---- Event code: 1001 Event message: Application is starting. Event time: 6/28/2011 8:34:40 AM Event time (UTC): 6/28/2011 3:34:40 PM Event ID: 07a3dc31e8804caca1ddc3b2101962e3 Event sequence: 1 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1/ROOT-3-129537488807712839 Trust level: Full Application Virtual Path: / Application Path: [snip]\RootApp\ Machine name: US-SEA-R9759B2 Process information: Process ID: 7624 Process name: w3wp.exe Account name: IIS APPPOOL\DefaultAppPool ---- Event code: 1001 Event message: Application is starting. Event time: 6/28/2011 8:34:40 AM Event time (UTC): 6/28/2011 3:34:40 PM Event ID: db304b519a084fa797fbcfe66fbb0b48 Event sequence: 1 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1/ROOT/MyApp-4-129537488808502885 Trust level: Full Application Virtual Path: /MyApp Application Path: [snip]\MyApp\ Machine name: US-SEA-R9759B2 Process information: Process ID: 7624 Process name: w3wp.exe Account name: IIS APPPOOL\DefaultAppPool 

MyApp application is in another application (RootApp). I would expect that there will be two log messages: the launch of MyApp and the launch of RootApp.

+8
appdomain
source share
2 answers

Have you accidentally set the number of workflows in the AppPool properties (Performance tab) to 2?

These properties may also have a parameter that allows your AppPool to be processed too often depending on the number or requests or any of these recycling parameters.

+2
source share

If I had to guess that there is something on your site that changes the files web.config, dll, aspx, asmx or some other file. Whenever these files change, a new instance of the web application is launched, and any new requests are received from this new web application, and old requests are served from the existing application. As soon as all old requests are completed, the old application is disconnected. This is useful for deployment because it does not break existing people's sessions, but that means you should not have anything that automatically changes web.config files for every request or something like that.

This page describes in more detail how this works http://technet.microsoft.com/en-us/library/cc759560(WS.10).aspx

+1
source share

All Articles