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

Replacing Process.Start with AppDomains

Background I have a Windows service that uses various third-party DLLs to perform work on PDF files. These operations can use quite a bit of system resources, and occasionally seem to suffer from memory leaks when errors occur. The DLLs are…
MikeWyatt
  • 7,842
  • 10
  • 50
  • 71
49
votes
4 answers

Facebook app creation app domain error

I'm trying to create Facebook app. Yet I had trouble right after creation wizard done his work. Changing nothing in what wizard created I've got an error: Error You have specified an App Domain but have not specified a valid integration…
user1851375
  • 491
  • 1
  • 4
  • 3
48
votes
7 answers

"Object has been disconnected or does not exist at the server" exception

I need to use cross-appdomain calls in my app, and sometimes I have this RemotingException: Object '/2fa53226_da41_42ba_b185_ec7d9c454712/ygiw+xfegmkhdinj7g2kpkhc_7.rem' has been disconnected or does not exist at the server. The target object is…
user626528
  • 13,999
  • 30
  • 78
  • 146
48
votes
3 answers

Running NUnit through Resharper 8 tests fail when crossing between projects due to AppDomain

I recently updated to Resharper 8, and when I tried to run a suite of projects. These tests contain two suites of integration tests that both use IISExpress to run a website, make web requests and check the responses. Running them in isolation is…
hawx
  • 1,313
  • 12
  • 10
47
votes
1 answer

In .NET 4.0, how do I 'sandbox' an in-memory assembly and execute a method?

Here is the reason why this question was being asked: www.devplusplus.com/Tests/CSharp/Hello_World. While similar questions were asked before, the many answers online have several issues: This must be done ".Net 4.0" style, not legacy mode. The…
Timothy Khouri
  • 31,315
  • 21
  • 88
  • 128
41
votes
5 answers

How to load a .NET assembly for reflection operations and subsequently unload it?

I'm writing a tool to report information about .NET applications deployed across environments and regions within my client's systems. I'd like to read the values of assembly attributes in these assemblies. This can be achieved using…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
39
votes
6 answers

How best to communicate between AppDomains?

I have an application that needs to send a moderately high volume of messages between a number of AppDomains. I know that I could implement this using remoting, but I have also noticed that there are cross-domain delegates. Has anyone looked at…
open-collar
  • 1,404
  • 1
  • 16
  • 22
33
votes
5 answers

Loading DLLs into a separate AppDomain

I want to load one or more DLLs dynamically so that they run with a different security or basepath than my main application. How do I load these DLLs into a separate AppDomain and instantiate objects from them?
Jon Turner
  • 2,932
  • 3
  • 22
  • 20
33
votes
1 answer

Static Fields in AppDomain

I'm experimenting ideas around using AppDomain to manage some legacy code contains lots of static fields in a multi-threaded environment. I read answers this question: How to use an AppDomain to limit a static class' scope for thread-safe use?,…
oscarkuo
  • 10,431
  • 6
  • 49
  • 62
33
votes
1 answer

How to avoid SerializationException: Type is not resolved for member XXX when testing a component that uses the LogicalCallContext

I've recently started hitting the following exception in my unit test (NUnit) code when EF tries to load information from App.config: System.Runtime.Serialization.SerializationException : Type is not resolved for member [my type name], [my assembly…
ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
33
votes
4 answers

Pass and execute delegate in separate AppDomain

I want to exceute some piece of code in separate AppDomain with delegate. How can I do this? UPD1: some more details about my problem My program processing some data (one iteration is: get some data from DB, evaluate it and create assemblies at…
lak-b
  • 2,115
  • 4
  • 18
  • 30
32
votes
4 answers

How can I prevent CompileAssemblyFromSource from leaking memory?

I have some C# code which is using CSharpCodeProvider.CompileAssemblyFromSource to create an assembly in memory. After the assembly has been garbage collected, my application uses more memory than it did before creating the assembly. My code is in…
Nogwater
  • 2,777
  • 3
  • 28
  • 28
26
votes
5 answers

facebook Error App Domain: [IP Address] is not a valid domain.?

I give my production server IP address as App domain in facebook application but it's not saved. It returns error as App domain is not valid. So that I cannot use my facebook connect API. Can we give IP address as App domain in FB application? If…
name-it
  • 2,238
  • 3
  • 19
  • 28
26
votes
2 answers

System.Addin - Creating secured ASP.NET MVC plugins

Lately my focus has been on creating an ASP.NET MVC application that can host 3rd party MVC plugins. Ideally, development of those plugins would follow these rules: Plugins can be developed in a standard MVC project, and be able to use all the…
Chris
  • 7,996
  • 11
  • 66
  • 98
25
votes
3 answers

How to properly unload an AppDomain using C#?

I have an application that loads external assemblies which I have no control over (similar to a plugin model where other people create and develop assemblies that are used by the main application). It loads them by creating new AppDomains for these…
Ray
  • 187,153
  • 97
  • 222
  • 204
1
2
3
94 95