AppDomain.DynamicDirectory Property

Gets the directory that the assembly resolver uses to probe for dynamically-created assemblies.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public string DynamicDirectory { get; }
/** @property */
public final String get_DynamicDirectory ()

public final function get DynamicDirectory () : String

Not applicable.

Property Value

Get the directory that the assembly resolver uses to probe for dynamically-created assemblies.

Exception typeCondition


The operation is attempted on an unloaded application domain.

This property is only available after an attempt has been made to load an assembly into this domain.

The following example creates an application domain and sets a directory for dynamic assemblies. The example uses the DynamicDirectory property to retrieve the name of the directory, so it can create the directory. The example then creates a dynamic assembly.

using System;
using System.Reflection;
using System.Reflection.Emit;

namespace AppDomainSnippets
    class ADDynamicBase
        // SetDynamicBase.exe
        static void Main(string[] args)
            // Create a new AppDomain.
            AppDomainSetup setup = new AppDomainSetup();
            // Need to set the application name before setting the dynamic base.
            setup.ApplicationName = "MyApplication";
            AppDomain domain = AppDomain.CreateDomain("MyDomain", null, setup);

            // Tell the domain to search for assemblies in subdirectories
            // of DynamicAssemblyDir.
            // Note that the actual dynamic directory has the form
            // <DynamicBase>\<number>\<ApplicationName>, rather than
            // simply <DynamicBase>.
            String dynamicDir = domain.DynamicDirectory;
            // The AssemblyBuilder won't create this directory automatically.

            // Define the dynamic assembly.
            AssemblyName asmName = new AssemblyName();
            asmName.Name = "DynamicHelloWorld";
            AssemblyBuilder asm = AppDomain.CurrentDomain.DefineDynamicAssembly
                (asmName, AssemblyBuilderAccess.Save, dynamicDir);

            // Define a dynamic module in the assembly.
            ModuleBuilder mod;
            mod = asm.DefineDynamicModule
                ("DynamicHelloWorld", "DynamicHelloWorld.dll");

            // Define the "HelloWorld" type in the module.
            TypeBuilder typ = mod.DefineType
                ("HelloWorld", TypeAttributes.Public);

            // Define the "SayHello" method.
            MethodBuilder meth = typ.DefineMethod
                ("SayHello", MethodAttributes.Public, null, null);
            ILGenerator il = meth.GetILGenerator();
            il.EmitWriteLine("Hello World!");

            // Complete the HelloWorld type.
            // Save the assembly to the dynamic assembly directory.

            // Launch MyExecutable.exe, which will load DynamicHelloWorld.dll.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions