This documentation is archived and is not being maintained.

AppDomainSetup.DynamicBase Property

Gets or sets the base directory where the directory for dynamically generated files is located.

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

public string DynamicBase { get; set; }
/** @property */
public final String get_DynamicBase ()

/** @property */
public final void set_DynamicBase (String value)

public final function get DynamicBase () : String

public final function set DynamicBase (value : String)

Property Value

A String that specifies the directory where the AppDomain.DynamicDirectory is located.

When an AppDomain is created, a directory called the Dynamic Directory can be specified to store dynamic assemblies. This directory is logically located under the ApplicationBase, although it can reside in another part of the directory.

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 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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0