Questions tagged [appdomainsetup]

AppDomainSetup provides configuration information for a new application domain which is an isolated environment in which Microsoft .NET assemblies can be sandboxed, granted specific permissions or PermissionSets and executed.

Definition:

An AppDomainSetup represents configuration information for a new application domain in which compiled Microsoft .NET assemblies can be isolated from other assemblies. 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.

When creating your application domains, the most important property is ApplicationBase which defines the root directory of the application and also used for probing for the types and assemblies in the directory specified by the ApplicationBase property.

Tag Usage:

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

Example (C#):

namespace AppDomainSetupExample
{
    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);

        }
    }
}
47 questions
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
14
votes
1 answer

Effect of LoaderOptimizationAttribute

I have written a small piece of code regarding the dynamic loading of assemblies and creating class instances from those assemblies, including an executable, a test lib to be dynamically loaded and a loader library to load dynamic assembly into a…
ali_bahoo
  • 4,732
  • 6
  • 41
  • 63
14
votes
1 answer

Why is AppDomainSetup.ShadowCopyFiles a string?

From the documentation: A String containing the string value "true" to indicate that shadow copying is turned on; or "false" to indicate that shadow copying is turned off. And its been this way since 1.1. Can anyone shed any light? I reflector'd…
Restore the Data Dumps
  • 38,967
  • 12
  • 96
  • 122
11
votes
3 answers

Custom AppDomain and PrivateBinPath

I'm using c# 4.0 and a console application just for testing, the following code does gives an exception. AppDomainSetup appSetup = new AppDomainSetup() { ApplicationName = "PluginsDomain", ApplicationBase =…
Ahmed Galal
  • 1,218
  • 1
  • 12
  • 24
9
votes
2 answers

What is the right way to set shadow copying for the default AppDomain

Relating to Can I make the default AppDomain use shadow copies of certain assemblies?, it describes a working solution to activate shadow copying within the default AppDomain for a specific directory. Basically it says to use these simple…
Bluesky
  • 103
  • 1
  • 1
  • 6
8
votes
2 answers

AppDomain.Load() fails with FileNotFoundException

I'm trying to load my plugin dll into separate AppDomain, but Load() method fails with FileNotFoundException. Moreover, it seems like setting PrivateBinPath property of AppDomainSetup has no effect, because in log I see "Initial PrivatePath = NULL".…
dedpichto
  • 220
  • 1
  • 4
  • 9
7
votes
1 answer

AppDomain.DynamicDirectory is not generated

I am creating a AppDomain using the below code String pa = @"C:\Users\user\AppData\Local\Temp\2\db5fjamk.xnl"; System.IO.Directory.CreateDirectory(pa); AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase =…
user2934433
  • 343
  • 1
  • 5
  • 20
7
votes
0 answers

App-domain evidence purpose?

I've been looking into the app domain in regards to creating a simple lightweight app that will sandbox code i want to run for me. I have a simple console app which allows me to request the specified code to run and set permissions etc.. However…
charliezz10
  • 195
  • 6
7
votes
2 answers

How to determine the \Temporary ASP.NET Files\root\{site hash} with PowerShell?

ASP.NET makes use of a temporary files directory to store files for Shadow Copying and Dynamic Compilation. A typical path will look like this. Note the hash on the end of the path. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET…
Daniel Little
  • 16,975
  • 12
  • 69
  • 93
6
votes
1 answer

Use .NET assembly without locking dll file

I have a windows service that executes once a day. It's only 10 minutes of action. I build the service's files in the bin folder of the website, because the service uses the website dll's. Unfortunately I noticed that when I installed the website…
Emil Jasiński
  • 391
  • 4
  • 13
4
votes
2 answers

Load assemblies with dependencies in a different AppDomain

My aim is to make a missing dependency check between 2 given folders. Imagine the following setup. Root\DirA\A.dll Root\DirB\B.dll B depends on A. So given these folders, I want to create a new AppDomain, load B.dll and have the dependency from…
Kostas Konstantinidis
  • 13,347
  • 10
  • 48
  • 61
3
votes
3 answers

Help needed with unloading .DLL's from AppDomain - Still not working even with ShadowCopy

I am trying to do the following. App A is the "mother app". It stays open. App B is just a .DLL where I write some classes that are derived from an interface specified in App A. Then, from App A, I will "import" classes from App B and run methods…
philmo
  • 205
  • 3
  • 7
3
votes
2 answers

PrivateBinPath outside ApplicationBase

My directory structure looks like this: -- Host Program Base |- HostProgram.exe |- SharedLIB.dll |-- LoadedLibs |- HostedLib.dll HostProgram.exe is attempting to load HostedLib.dll, which depends on SharedLib.dll. Thus, SharedLib.dll's…
Christian Stewart
  • 15,217
  • 20
  • 82
  • 139
3
votes
1 answer

Plugin AppDomains Workaround

When dealing with plugin assemblies in their own subdirectories, there is the well-known problem that these assemblies fail to load once they try to load their respective dependencies from their subdirectories. A solution is to load the plugins in…
O. R. Mapper
  • 20,083
  • 9
  • 69
  • 114
2
votes
1 answer

Configure Shadow Copy using app.config

Let me explain the scenario first. I have installed multiple copies (Say 10) of Services from a single install base. Now I want to update one of the dll. I need to Stop all the services, update the dll and restart the Service again. To avoid the…
Rajan Panneer Selvam
  • 1,279
  • 10
  • 24
1
2 3 4