Questions tagged [appdomain]

An application domain is an isolated environment in which Microsoft .NET assemblies can be sandboxed, granted specific permissions or PermissionSets and executed.

Definition:

An AppDomain represents an application domain in which compiled Microsoft .NET assemblies can be isolated from other assemblies (either in the root application or other, separate AppDomains). While AppDomains are typically used to sandbox third-party or otherwise untrusted code, they can also be used to separate code from the main process to prevent potential instability in a specific segment of an application.

Tag Usage:

The appdomain tag should be used when referencing issues related to the System.AppDomain class in Microsoft .NET or related remoting or process issues.

Example (C#):

namespace AppDomainExample
{
    using System;
    using System.IO;
    using System.Reflection;
    using System.Security;
    using System.Security.Permissions;
    using System.Security.Policy;

    class Program
    {
        static void Main(string[] args)
        {
            PermissionSet ps = new PermissionSet(PermissionState.None);
            ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            ps.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write, @"C:\"));

            var assembly = Assembly.GetExecutingAssembly();

            AppDomainSetup ads = new AppDomainSetup();
            ads.ApplicationBase = Path.GetFullPath(assembly.Location);
            StrongName fullTrustAssemblies = assembly.Evidence.GetHostEvidence<StrongName>();

            AppDomain domain = AppDomain.CreateDomain("foo", null, ads, ps, fullTrustAssemblies);

        }
    }
}
1415 questions
145
votes
3 answers

What is AppDomain?

What is an AppDomain? What are the benefits of AppDomains or why Microsoft brought the concept of AppDomains, what was the problem without AppDomains? Please elaborate.
Praveen Sharma
  • 4,511
  • 7
  • 27
  • 17
118
votes
3 answers

How can I implement ISerializable in .NET 4+ without violating inheritance security rules?

Background: Noda Time contains many serializable structs. While I dislike binary serialization, we received many requests to support it, back in the 1.x timeline. We support it by implementing the ISerializable interface. We've received a recent…
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
117
votes
8 answers

How to Load an Assembly to AppDomain with all references recursively?

I want to load to a new AppDomain some assembly which has a complex references tree (MyDll.dll -> Microsoft.Office.Interop.Excel.dll -> Microsoft.Vbe.Interop.dll -> Office.dll -> stdole.dll) As far as I understood, when an assembly is being loaded…
abatishchev
  • 98,240
  • 88
  • 296
  • 433
117
votes
6 answers

No AppDomains in .NET Core! Why?

Is there a strong reason why Microsoft chose not to support AppDomains in .NET Core? AppDomains are particularly useful when building long running server apps, where we may want to update the assemblies loaded by the server is a graceful manner,…
Aditya Pasumarthi
  • 1,219
  • 2
  • 9
  • 3
110
votes
8 answers

How can I reliably determine the type of a variable that is declared using var at design time?

I'm working on a completion (intellisense) facility for C# in emacs. The idea is, if a user types a fragment, then asks for completion via a particular keystroke combination, the completion facility will use .NET reflection to determine the…
Cheeso
  • 189,189
  • 101
  • 473
  • 713
95
votes
10 answers

Is there a way to force all referenced assemblies to be loaded into the app domain?

My projects are set up like this: Project "Definition" Project "Implementation" Project "Consumer" Project "Consumer" references both "Definition" and "Implementation", but does not statically reference any types in "Implementation". When the…
Daniel Schaffer
  • 56,753
  • 31
  • 116
  • 165
89
votes
4 answers

What is a .NET application domain?

In particular, what are the implications of running code in two different application domains? How is data normally passed across the application domain boundary? Is it the same as passing data across the process boundary? I'm curious to know more…
Luke
  • 18,585
  • 24
  • 87
  • 110
82
votes
3 answers

I don't understand Application Domains

.NET has this concept of Application Domains which from what I understand can be used to load an assembly into memory. I've done some research on Application Domains as well as go to my local book store for some additional knowledge on this subject…
Jeremy Edwards
  • 14,620
  • 17
  • 74
  • 99
77
votes
5 answers

Usage of AppDomain in C#

What is the most important use of AppDomains in C#?
Nipun
  • 1,465
  • 4
  • 20
  • 28
64
votes
5 answers

How to detect when application terminates?

This is a follow up to my initial question and I would like to present my findings and ask for corrections, ideas and insights. My findings (or rather interpretations) come from people's answers to my previous question, reading MSDN .NET 3.5…
user65199
63
votes
10 answers

AppDomain and MarshalByRefObject life time : how to avoid RemotingException?

When a MarshalByRef object is passed from an AppDomain (1) to another (2), if you wait 6 mins before calling a method on it in the second AppDomain (2) you will get a RemotingException : System.Runtime.Remoting.RemotingException: Object [...] has…
Guillaume
  • 12,824
  • 3
  • 40
  • 48
62
votes
3 answers

List AppDomains in Process

Is there any possibility how to enumerate AppDomains within Process?
marc
  • 847
  • 1
  • 8
  • 9
53
votes
8 answers

How to unload an assembly from the primary AppDomain?

I would like to know how to unload an assembly that is loaded into the main AppDomain. I have the following code: var assembly = Assembly.LoadFrom( FilePathHere ); I need/want to be able to unload this assembly when I am done. Thanks for your help.
Derik Whittaker
  • 832
  • 1
  • 7
  • 10
50
votes
7 answers

Good example of use of AppDomain

I keep getting asked about AppDomains in interviews, and I know the basics: they are an isolation level within an application (making them different from applications) they can have threads (making them different from threads) exceptions in one…
hughdbrown
  • 47,733
  • 20
  • 85
  • 108
50
votes
3 answers

How to keep ASP.NET assemblies in AppDomain alive?

Scenario: I've an n-Tier enterprise ASP.NET application deployed using Web Deployment Projects. All tiers produce independent assemblies that is consumed by the ASP.NET application. Problem: When I run the app. for the first time after deployment it…
this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137
1
2 3
94 95