This documentation is archived and is not being maintained.

AppDomain.BaseDirectory Property

Gets the base directory that the assembly resolver used to probe for assemblies.

[Visual Basic]
Public Overridable ReadOnly Property BaseDirectory As String  _
   Implements _AppDomain.BaseDirectory
[C#]
public virtual string BaseDirectory {get;}
[C++]
public: __property virtual String* get_BaseDirectory();
[JScript]
public function get BaseDirectory() : String;

Property Value

The base directory that the assembly resolver uses to probe for assemblies.

Implements

_AppDomain.BaseDirectory

Exceptions

Exception Type Condition
AppDomainUnloadedException Operations are attempted on an unloaded application domain.
SecurityException The caller does not have the required permission.

Remarks

This property corresponds to the assembly resolver's APPBASE.

Example

[Visual Basic] 
Imports System
Imports System.Reflection
Imports System.Security.Policy
 'for evidence object

Class ADSetup
   
   Public Shared Sub Main()
      ' Create the application domain setup information.
      Dim domaininfo As New AppDomainSetup()
      domaininfo.ConfigurationFile = "file:///" + System.Environment.CurrentDirectory + "ADSetup.exe.config"
      domaininfo.ApplicationBase = "file:///" + System.Environment.CurrentDirectory
      
      'Create evidence for the new appdomain from evidence of the current application domain.
      Dim adevidence As Evidence = AppDomain.CurrentDomain.Evidence
      
      ' Create appdomain.
      Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", adevidence, domaininfo)
      
      ' Write out the application domain information.
      Console.WriteLine(("Host domain: " + AppDomain.CurrentDomain.FriendlyName))
      Console.WriteLine(("child domain: " + domain.FriendlyName))
      Console.WriteLine()
      Console.WriteLine(("Configuration file is: " + domain.SetupInformation.ConfigurationFile))
      Console.WriteLine(("Application Base Directory is: " + domain.BaseDirectory))
      
      
      AppDomain.Unload(domain)
   End Sub 'Main 
End Class 'ADSetup 

[C#] 
using System;
using System.Reflection;
using System.Security.Policy;  //for evidence object
class ADSetup
{
    public static void Main()
    {
        // Create application domain setup information
        AppDomainSetup domaininfo = new AppDomainSetup();
        domaininfo.ConfigurationFile = "file:///" + System.Environment.CurrentDirectory + "ADSetup.exe.config";
        domaininfo.ApplicationBase = "file:///" + System.Environment.CurrentDirectory;

        //Create evidence for the new appdomain from evidence of the current application domain
        Evidence adevidence = AppDomain.CurrentDomain.Evidence;

        // Create appdomain
        AppDomain domain = AppDomain.CreateDomain("MyDomain", adevidence, domaininfo);

        // Write out application domain information
        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
        Console.WriteLine("child domain: " + domain.FriendlyName);
        Console.WriteLine();
        Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile);
        Console.WriteLine("Application Base Directory is: " + domain.BaseDirectory);


        AppDomain.Unload(domain);
    
        
    }
    
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Security::Policy;  //for evidence Object

int main() {
   // Create application domain setup information
   AppDomainSetup* domaininfo = new AppDomainSetup();
   domaininfo->ConfigurationFile =
      String::Format(S"file:///{0}ADSetup.exe.config", System::Environment::CurrentDirectory);
   domaininfo->ApplicationBase = String::Format(S"file:///{0}", System::Environment::CurrentDirectory);

   //Create evidence for the new appdomain from evidence of the current application domain
   Evidence* adevidence = AppDomain::CurrentDomain->Evidence;

   // Create appdomain
   AppDomain*  domain = AppDomain::CreateDomain(S"MyDomain", adevidence, domaininfo);

   // Write out application domain information
   Console::WriteLine(S"Host domain: {0}", AppDomain::CurrentDomain->FriendlyName);
   Console::WriteLine(S"child domain: {0}", domain->FriendlyName);
   Console::WriteLine();
   Console::WriteLine(S"Configuration file is: {0}", domain->SetupInformation->ConfigurationFile);
   Console::WriteLine(S"Application Base Directory is: {0}", domain->BaseDirectory);

   AppDomain::Unload(domain);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

AppDomain Class | AppDomain Members | System Namespace

Show: