Net4x.AppDomain 2.0.0

dotnet add package Net4x.AppDomain --version 2.0.0
                    
NuGet\Install-Package Net4x.AppDomain -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Net4x.AppDomain" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.AppDomain" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Net4x.AppDomain" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Net4x.AppDomain --version 2.0.0
                    
#r "nuget: Net4x.AppDomain, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Net4x.AppDomain@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Net4x.AppDomain&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Net4x.AppDomain&version=2.0.0
                    
Install as a Cake Tool

Net4x.AppDomain

Classic AppDomain isolation for .NET Standard 2.0 and .NET 8+, where each domain is a real operating-system process and cross-domain calls travel over Net4x.Runtime.Remoting.

Isolation is stronger than a .NET Framework application domain ever provided: a child that stack-overflows, corrupts native memory, or calls Environment.FailFast cannot bring the parent down.

Quick start

using System;                       // the extensions live in System — no extra using needed

var domain = AppDomain.CurrentDomain.CreateChildDomain("worker");

var worker = domain.CreateInstanceAndUnwrap<Worker>();
Console.WriteLine(worker.ProcessId);          // a different process id
Console.WriteLine(worker.Compute(21));

domain.Unload();                              // or: using var domain = ...

The worker is an ordinary MarshalByRefObject. Members must be virtual so calls can be intercepted — if one is not, domain creation fails and tells you which:

public class Worker : MarshalByRefObject
{
    public virtual int Compute(int x) => x * 2;
    public virtual int ProcessId => Environment.ProcessId;
}

Migrating from classic AppDomain

C# has no static extension methods, so the two statics change; everything else keeps its name.

// before                                     after
AppDomain.CreateDomain("worker")              AppDomain.CurrentDomain.CreateChildDomain("worker")
AppDomain.Unload(domain)                      domain.Unload()

// unchanged
domain.CreateInstanceAndUnwrap(asm, type)
domain.DoCallBack(SomeStaticMethod)
domain.SetData("k", v) / domain.GetData("k")
domain.FriendlyName / domain.BaseDirectory / domain.IsDefaultAppDomain()

AppDomainSetup becomes AppDomainSetup2 (the platform owns the original name on .NET 8), keeping the classic property names plus process-specific ones:

var setup = new AppDomainSetup2
{
    ApplicationBase = @"C:\plugins\acme",
    PrivateBinPath  = "lib",
    StartupTimeout  = TimeSpan.FromSeconds(30),
};
setup.InitialData["tenant"] = "acme";

using var domain = AppDomain.CurrentDomain.CreateChildDomain("acme-plugin", setup);

Members that could not keep their signature

Assembly, AppDomainSetup and evidence cannot cross a process boundary.

Classic Here
Assembly Load(string) AssemblyName LoadAssembly(string)
Assembly[] GetAssemblies() AssemblyName[] GetLoadedAssemblies()
event ResolveEventHandler AssemblyResolve event DomainAssemblyResolveHandler AssemblyResolve — answer with a path or bytes
AppDomainSetup SetupInformation AppDomainSetup2 Setup
AppDomain.CreateDomain(...) AppDomain.CurrentDomain.CreateChildDomain(...)
AppDomain.Unload(domain) domain.Unload()

Classic properties with no meaning off .NET Framework — ShadowCopyFiles, LoaderOptimization, evidence, permission sets — are deliberately not declared. A setting that silently does nothing is worse than a compile error.

Callbacks and events

domain.DoCallBack(Plugin.Initialize);            // runs in the child

domain.AssemblyResolve += (d, request) =>        // child could not resolve something
    AssemblyResolveResponse.FromPath(Locate(request.Name));

domain.UnhandledException += (s, e) => Log(e.ExceptionText);
domain.OutputReceived    += (s, e) => Log(e.Line);
domain.DomainUnloaded    += (s, e) => Log("domain gone");

DoCallBack requires a static method, or an instance method on a MarshalByRefObject. A lambda capturing local state compiles to a closure with no identity the child can reach, and is rejected rather than silently running in the wrong process.

Lifetime

Unload() asks the domain to exit, then kills it after UnloadTimeout. Calls into an unloaded or crashed domain throw AppDomainUnloadedException. A child watches its parent and exits if the parent dies, so a crashed parent leaves no orphans. ChildAppDomain is IDisposable.

Requirements and caveats

The package ships a host program under tools/net8.0 which is launched per domain, normally through the dotnet muxer. If the parent is self-contained or single-file and the muxer cannot be found, point AppDomainSetup2.HostExecutable at a host executable directly; the error message lists everywhere it looked.

Domains communicate over loopback TCP on an ephemeral port, bound to 127.0.0.1 and reached through unguessable capability URIs. That is hardening, not a security boundary — another process running as the same user can reach a domain. Do not use domains to isolate code you do not trust.

A domain costs roughly 50–100 ms to start, against about 1 ms for a real application domain. Pool and reuse domains rather than creating one per unit of work.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Net4x.AppDomain:

Package Downloads
Net4x.AppDomainTaskLibrary

AppDomainTask Library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 31 7/30/2026