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
18
votes
3 answers

First WCF connection made in new AppDomain is very slow

I have a library that I use that uses WCF to call an http service to get settings. Normally the first call takes ~100 milliseconds and subsequent calls takes only a few milliseconds. But I have found that when I create a new AppDomain the first WCF…
BrandonAGr
  • 5,827
  • 5
  • 47
  • 72
17
votes
4 answers

Use the [Serializable] attribute or subclassing from MarshalByRefObject?

I'd like to use an object across AppDomains. For this I can use the [Serializeable] attribute: [Serializable] class MyClass { public string GetSomeString() { return "someString" } } Or subclass from MarshalByRefObject: class MyClass:…
Theo Lenndorff
  • 4,556
  • 3
  • 28
  • 43
17
votes
5 answers

Self-update / shadow-copy with Asp.Net Core

I'm writing a Asp.Net Core application which should be able to update itself (replace its own binaries while running). This MSDN article describes shadow copying with the classical .Net framework, which would be exactly what I need. But the whole…
Robert Hegner
  • 9,014
  • 7
  • 62
  • 98
17
votes
1 answer

Under what circumstances will .NET processes and AppDomains share loaded assemblies in memory?

I'm looking for more details around when and how .NET applications share loaded assemblies. I'm interested in sharing between OS processes, but also between AppDomains within the same process. Sharing assemblies reduces system memory usage by…
redcalx
  • 8,177
  • 4
  • 56
  • 105
17
votes
5 answers

ASP.NET restarts when a folder is created, renamed or deleted

UPDATE -- process to replicate issue: 1) Create a website project at c:\projects\restart-demo 2) Add default web.config and a dummy aspx page test.aspx 3) Map IIS to point to the root folder c:\projects\restart-demo 4) Monitor application restarts…
frankadelic
  • 20,543
  • 37
  • 111
  • 164
17
votes
2 answers

How do I pass CancellationToken across AppDomain boundary?

I have a command object, doing work based on a request from a request queue. This particular command will execute its work in a child appdomain. Part of doing its work in the child appdomain involves blocking on a ConcurrentQueue operation (eg, Add…
gap
  • 2,766
  • 2
  • 28
  • 37
17
votes
4 answers

Where can I purchase .app TLD?

Where can I purchase a .app Top Level Domain (TLD)? I've gone to Network Solutions, GoDaddy, etc and can't find someone who is selling .app domains (e.g. http://example.app).
nickb
  • 9,140
  • 11
  • 39
  • 48
16
votes
5 answers

What are app domains used for?

I understand roughly what an AppDomain is, however I don't fully understand the uses for an AppDomain. I'm involved in a large server based C# / C++ application and I'm wondering how using AppDomains could improve stability / security /…
Justin
  • 84,773
  • 49
  • 224
  • 367
16
votes
2 answers

Loading app.config into the AppDomain

I can't get the App.Config file to load into the App Domain. I'm using [System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $config_path) from Powershell Calling .NET Assembly that uses App.config but the App.Config file is still not…
Alexandre Rondeau
  • 2,667
  • 24
  • 31
16
votes
1 answer

SerializationException: Type is not resolved for member "..."

I've been trying to dynamically load an assembly to an AppDomain. I need to do it because I want to call a method dynamically, but don't keep the handle to the DLL while my app is running, so that it can be replaced, if needed. But I'm getting this…
gsb
  • 1,219
  • 1
  • 16
  • 31
16
votes
2 answers

AppDomain address space

First, the question: do CLR specifications guarantee that the code executing in multiple app domains within the same process will share the same address space? By "sharing the address space" I mean that pointers to memory allocated in one of the app…
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
15
votes
1 answer

Cross-AppDomain call corrupts the runtime

This was originally a much more lengthy question, but now I have constructed a smaller usable example code, so the original text is no longer relevant. I have two projects, one containing a single struct with no members, named TestType. This project…
IS4
  • 11,945
  • 2
  • 47
  • 86
15
votes
4 answers

CPU and Memory Cap for an AppDomain

I want to host an exe in an appdomain and assign a CPU and Memory cap to it so that it does not use more than the assigned processing power. Is this possible to do and how?
Hemanshu Bhojak
  • 16,972
  • 16
  • 49
  • 64
15
votes
2 answers

In .NET, are static constructors called when a new AppDomain is created?

When I create a new AppDomain using AppDomain.CreateDomain in C#, will static constructors be called as asseblies are loaded inside the newly created AppDomain? The assemblies in question have already been loaded into the current domain.
ngoozeff
  • 4,576
  • 3
  • 28
  • 21
15
votes
1 answer

Deadlock when combining app domain remoting and tasks

My app needs to load plugins into separate app domains and then execute some code inside of them asynchronously. I've written some code to wrap Task in marshallable types: static class RemoteTask { public static async Task
Cory Nelson
  • 29,236
  • 5
  • 72
  • 110