BUG: Multiple ASP.NET Application Restarts Occur Every One to Five Minutes (319947)



The information in this article applies to:

  • Microsoft ASP.NET (included with the .NET Framework) 1.0
  • Microsoft ASP.NET (included with the .NET Framework 1.1)

This article was previously published under Q319947

SYMPTOMS

When many new .aspx, .ascx, or .asmx files are propagated to a server, the server may report successive application restarts for some time afterward. This problem may show up in several different ways:
  • The ASP.NET\Application Restarts performance counter is incremented for each restart.
  • If you use in-memory session state, session variables are lost.
  • Application state is lost.
  • The Application_Start and the Application_End events are executed repeatedly.

CAUSE

By default, when you update fewer than 15 files in ASP.NET, the files are compiled and loaded into memory with the old versions of the compiled files. This is a feature of the .NET common language runtime named side-by-side execution.

However, the old versions of the compiled code remain in memory indefinitely with side-by-side execution. When you update many files (for example, more than 30 files), if you do not restart the application to clear the old versions from memory, too much memory may be used. To work around this problem, ASP.NET has a feature in which the application is automatically restarted after a particular number of files are updated.

The restart should occur only one time for the whole list of updated files. After the application restart, old versions should not reside in memory. Therefore, the application should not have to be restarted to recompile new versions of files. However, this problem occurs when you load many new .aspx or .ascx files to the server (for example, 61 files). The server unloads the application when the first 15 files are recompiled and every time another 15 files are recompiled until the server reaches 61. This results in four application restarts even though only one is required.

RESOLUTION

To avoid an automatic restart based on the number of updated files, set the numRecompilesBeforeAppRestart attribute in the Machine.config file from the default of 15 to a number that is larger than the number of files that will be updated between planned application restarts. If you set numRecompilesBeforeAppRestart to a large number, you may want to restart the application manually to free the memory that the old versions of the assemblies use.

NOTE: If ASP.NET consumes too much memory, ASP.NET restarts that application automatically.

If you are updating a known number of files, and if you want to restart the application automatically, set numRecompilesBeforeAppRestart to a number that is just less than the number of files that will be updated. This causes a single application restart with a small number of old assemblies in memory. For example, set numRecompilesBeforeAppRestart as follows:
        <compilation debug="false" explicit="true" numRecompilesBeforeAppRestart="50" defaultLanguage="vb">
				

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

You may see this behavior with inline Active Server Pages (ASP) code in which the executable ASP code is in the .aspx or .ascx file. However, you do not see this behavior when you use the code-behind model to build the ASP.NET application. In the code-behind model, the compiled code is in the form of a dynamic-link library (DLL) and is placed in the Bin directory for that application. This causes the application restart, so you do not see the exact behavior that is mentioned in this article.

REFERENCES

For more information about the <processModel> element, see the MSDN documentation: For additional information about ASP.NET features, click the article number below to view the article in the Microsoft Knowledge Base:

305140 INFO: ASP.NET Roadmap


Modification Type:MajorLast Reviewed:1/19/2004
Keywords:kbbug kbConfig kbHttpRuntime kbpending KB319947