Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an AppDomain for every C# program?

Tags:

c#

.net

appdomain

Is there an AppDomain for every C# program even if we do not specifically create an AppDomain? Why is it required? I have read about third party assemblies crashing the entire application if we do not load them into separate AppDomain. I didn't get that point well. Can anyone explain this also.

like image 260
softwarematter Avatar asked Apr 22 '09 09:04

softwarematter


2 Answers

AppDomain is pretty much like a process, it's an infrastructure that your application runs in. A .NET assembly needs to be loaded in an AppDomain in order to be run. It's not required to load third party assemblies into separate AppDomains, but if you do, it provides isolation between them (like two separate processes) and malfunction in one will not affect the other. Application domains can be unloaded independently.

As an example, SQL Server use AppDomains to load CLR assemblies safely in its process.

like image 139
mmx Avatar answered Sep 28 '22 04:09

mmx


I have read about 3rd party assemblies causing crash if we do not make use of AppDomain

I think you are talking about loading other assemblies in to separate app domains. That way they can be isolated from your address space to prevent a crash in their code affecting you. The cost is that communicating with an assembly in a seperate app domain is more difficult and has a perf penalty as all calls need to be martialed across the app domain boundary.

This is a fairly advance topic, I'd recommend reading up in Richter (other books are avaialable).

like image 29
Steve Avatar answered Sep 28 '22 03:09

Steve