6

Since dynamic assembly loading requires appdomain loading to enable killing the assembly with unloading related appdomain, is there a "max" number appdomains in a process to be loaded? I am thinking of a server based application that each user can run his proprietary C# code dynamically. But what if, say, 2000 users log in and load their codes? Are there any possible restrictions I might encounter besides the number of appdomians?

thanks.

ali_bahoo
  • 4,732
  • 6
  • 41
  • 63

3 Answers3

7

Almost all CLR limits are based on "as memory permits". The only exception I know of is the number of members of a class, restricted to 65536. That's based on the definition of a token value. Nothing like that for AppDomains.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 4
    ASP.NET doesn't create 1 `AppDomain` per request. It is basically 1 per ASP.NET web site. That `AppDomain` stays alive for quite a while, though there are conditions that will automatically "recycle" it. I'm not sure what SQL Server does, but a new `AppDomain` is not created for each query. – Jason Kresowaty Nov 10 '10 at 00:53
  • @bin - fault isolation is the key afaik. Once a thread dies on an unhandled exception, the ad is junk. It cannot be that *one* page request that bombs kills all other concurrent ones. Recycling ones that didn't die sounds maybe. I don't know the exact rules. – Hans Passant Nov 10 '10 at 01:19
  • ASP.NET has a big old try/catch high on the stack. Funnels into the `HttpApplication.Error` event. If there is no handler, it shows the default 500 error page. If something really bad happens, ASP.NET will recycle the domain, or the entire worker process might restart, but most unhandled exceptions do not cause these things. – Jason Kresowaty Nov 10 '10 at 01:30
5

I don't believe that there is a definitive maximum value in-built in the CLR. Rather it would be the amount of memory left which determines if you can dynamically load a new appdomain.

I'll do a bit of research, but I don't think there is a value set for this.

EDIT:

Here's another post which might help clear things up.

Jason Evans
  • 28,906
  • 14
  • 90
  • 154
1

Mostly it would be defined by your OS limits. Your x86 machine can't use more than 4GB in memory for a process [only 2GB in user mode]. If you go for x64 you have a much bigger limit. From what I know there is no such limit to the number of Application Domains you can create.

Rahul Soni
  • 4,941
  • 3
  • 35
  • 58