Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double App Domains in ASP.NET 4 application

I've got an ASP.NET application running on IIS 7 with multiple application domains, and I can't fathom why there are multiple app domains in a single process. I've grepped my code base, and I'm not explicitly creating a second application domain. Is it possible that a recycle has failed to time out?

  • These double domains will persist for sometime.
  • If a recycle occurs because of a web config or binary change, both app domains will go down, and two new ones will start up.
  • These servers are subject to several binary patches and IISResets per day - sometimes there are 2 domains, sometimes only 1.
  • Web gardening is disabled.
  • I discovered this because there is a timer in the application heart-beating to the database, and noticed one day the server had two heartbeats.

In windbg, !dumpdomain shows me the following result: (filtered to only show names of app domains):

Line 59: Name:               None
Line 66: Name:               None
Line 372: Name:               DefaultDomain
Line 460: Name:               /LM/W3SVC/1/ROOT/MyAppDomain-1-129882892717131250
Line 4437: Name:               /LM/W3SVC/1/ROOT/MyAppDomain-4-129285605131450579
like image 779
Dlongnecker Avatar asked Jun 06 '12 22:06

Dlongnecker


People also ask

How many application domain can be used in single process?

Process A runs managed code with one application domain while Process B runs managed code has three application domains. Note that Process C which runs unmanaged code has no application domain.

How many application domain can be linked to a website in IIS?

One IIS server may have multiple application pools. One web application binds to one application pool. One application pool may have more than one worker process (when Web Garden is enable). One worker process can have multiple app domains.

What is application domain in asp net with example?

An application domain forms an isolation boundary for security, versioning, reliability, and unloading of managed code. A thread is the operating system construct used by the common language runtime to execute code.

What is the app domain in the .NET Framework What is the use of it?

Application domains provide a unit of isolation for the common language runtime. They are created and run inside a process. Application domains are usually created by a runtime host, which is an application responsible for loading the runtime into a process and executing user code within an application domain.


Video Answer


1 Answers

  1. Even though you aren't creating an AppDomain, a library that you are using might be. What third-party components are you using? Do you have any Inversion of Control or Dynamic Proxy libraries that might be responsible? Here's an explanation of this happening with Castle.

  2. Are you sure the application is only running in one place in IIS? It's possible to have multiple IIS sites/applications running off of the same files. This would be consistent with (1) getting your debug info from the db, rather than the app, and (2) the recycle due to editing web.config consistently resulting in duplicate domains. If one location is more commonly accessed than the other this could explain why there is sometimes only one AppDomain.

  3. If you are leveraging ASP.NET's dynamic compilation and shadow copying feature, ASP.NET will at times have multiple AppDomains. Jim Schubert wrote an article called ASP.NET, AppDomains, and shadow-copying which explains this in more detail as well as makes several suggestions as to how to modify web.config to customize this. He also has a helpful answer over at Does my ASP.NET application stop executing if I overwrite the DLLs? Shadow copying can be disabled by setting <hostingEnvironment shadowCopyBinAssemblies="false" />.

Update

I got sucked into Jim Schubert's blog and ended up reading this unrelated post on Allowing Only A Single Instance of a .NET application. If all else fails, you could use this approach to ensure only one instance of the application is running.

like image 133
smartcaveman Avatar answered Sep 26 '22 02:09

smartcaveman