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
25
votes
1 answer

Broken tab navigation in popup with WPF user control hosted inside Winforms in default AppDomain

I have a WPF user control that uses a Popup. This control is a plugin and can be loaded in the main AppDomain or in a separate AppDomain, and it is hosted in a Winforms form using ElementHost. When the plugin is loaded in the main AppDomain, and the…
lordjeb
  • 1,286
  • 9
  • 14
24
votes
3 answers

Loading/Unloading assembly in different AppDomain

I need to execute a method in an assembly loaded during runtime. Now I want to unload those loaded assemblies after the method call. I know that I need a new AppDomain so I can unload the libraries. But here, the problem arises. The assemblies going…
Scoregraphic
  • 7,110
  • 4
  • 42
  • 64
23
votes
2 answers

Static Variable Instances and AppDomains, what is happening?

I have public static class A { public static string ConnString; } [Serializable] public class Test{ // Accesing A's field; public string ConnString{get{return A.ConnString;}set{A.ConnString=value;}} } void Main() { A.ConnString =…
Thanasis Ioannidis
  • 2,981
  • 1
  • 30
  • 50
23
votes
2 answers

How do I create an application domain and run my application in it?

I need to create a custom application domain to work around a bug in the .NET runtime's default behavior. None of the sample code I've seen online is helpful since I don't know where to place it, or what it needs to replace within my Main() method.
22
votes
2 answers

How do I dynamically load raw assemblies that contains unmanaged code?(bypassing 'Unverifiable code failed policy check' exception)

I'm going to give an example of using System.Data.SQLite.DLL which is a mixed assembly with unmanaged code: If I execute this : var assembly= Assembly.LoadFrom("System.Data.SQLite.DLL") No exceptions are thrown, but if I do this : var…
Thiago Padilha
  • 4,590
  • 5
  • 44
  • 69
22
votes
1 answer

AppDomain.CreateInstanceFromAndUnwrap - Unable to cast transparent proxy

I'm writing a .NET library to inject managed DLLs into external processes. My current approach is: Use CreateRemoteThread to force the target process to call LoadLibrary on an unmanaged bootstrap DLL. From this point we're executing code in the…
flukes1
  • 585
  • 1
  • 7
  • 11
20
votes
3 answers

Can a C# .dll assembly contain an entry point?

My goal is to create an executable that will start a shadow copied application. The trick is, I want this starter program to have no external dependencies and not have to contain any knowledge about the program it has to start. I also want it to be…
Sean
  • 533
  • 1
  • 5
  • 6
20
votes
4 answers

Sharing data between AppDomains

I have a process that can have multiple AppDomains. Each AppDomain collect some statistics. After a specified time, I want to accumulate these statistic and save them into a file. One way to do this is Remoting, which I want to avoid. The only…
ata
  • 8,853
  • 8
  • 42
  • 68
20
votes
1 answer

Accessing the default app domain

I am looking for a way to find the default app domain in my process. Note than the current app domain may be different from the default one, for example when my code is running inside NUnit. I know that I can list all the app domains in the process…
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
19
votes
3 answers

Loading multiple versions of the same assembly

I'm working with a third-party assembly and unfortunately I now need to load their latest and a previous version into my project so at runtime I can decide which one to load. I only ever need one, not both. With this in mind, I am also dependent…
GT.
  • 545
  • 1
  • 8
  • 18
19
votes
3 answers

What is the minimum Cross AppDomain communication performance penalty?

I am trying to minimize the performance penalty of communicating across AppDomains in the same machine. In my toy example, Class A is loaded in AppDomain 1. It creates an AppDomain 2 and loads there an instance of Class 2 (Class 2 inherits from…
Yiannis
  • 880
  • 1
  • 7
  • 14
19
votes
5 answers

log4net across appdomains

I have an application which initializes log4net from one appdomain and needs to use it in another appdomain. Is it supported? If not, should I initialize log4net from each appdomain? Is there a risk in multiple initializations in the same…
Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158
18
votes
2 answers

Load Assembly in New AppDomain without loading it in Parent AppDomain

I am attempting to load a dll into a console app and then unload it and delete the file completely. The problem I am having is that the act of loading the dll in its own AppDomain creates a reference in the Parent AppDomain thus not allowing me to…
Al Katawazi
  • 7,192
  • 6
  • 26
  • 39
18
votes
1 answer

DLLs loaded from wrong AppplicationBase when trying to load mixed C# and C++/CLI dlls in a new AppDomain

We have a large .NET solution with both C# and C++/CLI projects which reference each other. We also have several unit testing projects. We've recently upgraded from Visual Studio 2010 & .NET 4.0 to Visual Studio 4.5 & .NET 4.5, and now when we try…
Yoav Shany
  • 181
  • 1
  • 6
18
votes
4 answers

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…
Dlongnecker
  • 3,008
  • 3
  • 25
  • 40
1 2
3
94 95