Export (0) Print
Expand All

AppDomain.SetDynamicBase Method

NOTE: This method is now obsolete.

Establishes the specified directory path as the location where dynamically generated files are stored and accessed.

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

[ObsoleteAttribute("AppDomain.SetDynamicBase has been deprecated. Please investigate the use of AppDomainSetup.DynamicBase instead. http://go.microsoft.com/fwlink/?linkid=14202")] 
public void SetDynamicBase (
	string path
)
/** @attribute ObsoleteAttribute("AppDomain.SetDynamicBase has been deprecated. Please investigate the use of AppDomainSetup.DynamicBase instead. http://go.microsoft.com/fwlink/?linkid=14202") */ 
public void SetDynamicBase (
	String path
)
ObsoleteAttribute("AppDomain.SetDynamicBase has been deprecated. Please investigate the use of AppDomainSetup.DynamicBase instead. http://go.microsoft.com/fwlink/?linkid=14202") 
public function SetDynamicBase (
	path : String
)

Parameters

path

The fully qualified path to where dynamic assemblies are stored.

Exception typeCondition

AppDomainUnloadedException

Operations are attempted on an unloaded application domain.

This method sets the DynamicBase property of the internal AppDomainSetup associated with this instance.

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.
			domain.SetDynamicBase("C:\\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.
			if(!System.IO.Directory.Exists(dynamicDir))
			{
				System.IO.Directory.CreateDirectory(dynamicDir);
			}

			// 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!");
			il.Emit(OpCodes.Ret);

			// Complete the HelloWorld type.
			typ.CreateType();
			
			// Save the assembly to the dynamic assembly directory.
			asm.Save("DynamicHelloWorld.dll");

			// Launch MyExecutable.exe, which will load DynamicHelloWorld.dll.
			domain.ExecuteAssembly("MyExecutable.exe");
		}
	}
}

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: 1.0, 1.1
Obsolete (compiler warning) in 2.0

Community Additions

ADD
Show:
© 2015 Microsoft