Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ApplicationName Property

AppDomainSetup.ApplicationName Property

Gets or sets the name of the application.

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

'Declaration
Public Property ApplicationName As String

Property Value

Type: System.String
The name of the application.

Implements

IAppDomainSetup.ApplicationName

The following example shows how to set the ApplicationName property when you create a new application domain.

The example creates a new application domain, and then calls the AppDomain.CreateInstanceAndUnwrap method to load the example assembly into the new application domain and create an instance of the Worker class. The Worker class inherits MarshalByRefObject, so the example can use the proxy returned by CreateInstanceAndUnwrap to call the TestLoad method.

The TestLoad method loads an assembly that you specify. You must either specify a valid, fully qualified assembly name, or comment out the Load(String) method. The TestLoad method lists the assemblies that are loaded into the new application domain, showing that your specified assembly and the example assembly are loaded.

The example uses the LoaderOptimizationAttribute attribute to tell the assembly loader how the application will share code across application domains.

Imports System
Imports System.Reflection
Imports System.Security.Policy
'Imports System.Data 
 'for evidence object 

Class ADMultiDomain

   ' The following attribute indicates to loader that multiple application  
   ' domains are used in this application.
   <LoaderOptimizationAttribute(LoaderOptimization.MultiDomainHost)>  _
   Public Shared Sub Main()
      ' Create application domain setup information for new application domain. 
      Dim domaininfo As New AppDomainSetup()
      domaininfo.ApplicationBase = System.Environment.CurrentDirectory
      domaininfo.ApplicationName = "MyMultiDomain Application" 

      'Create evidence for the new appdomain from evidence of current application domain. 
      Dim adevidence As Evidence = AppDomain.CurrentDomain.Evidence

      ' Create appdomain. 
      Dim newDomain As AppDomain = AppDomain.CreateDomain("MyMultiDomain", adevidence, domaininfo)

      'Load an assembly into the new application domain. 
      Dim w As Worker = CType( _
         newDomain.CreateInstanceAndUnwrap( 
            GetType(Worker).Assembly().GetName().Name, "Worker"), 
            Worker) 
      w.TestLoad()

      'Unload the application domain, which also unloads the assembly.
      AppDomain.Unload(newDomain)

   End Sub 'Main
End Class 'ADMultiDomain

Class Worker
   Inherits MarshalByRefObject

   Friend Sub TestLoad()
      ' You must supply a valid assembly display name here.
      [Assembly].Load("Text assembly name, Culture, PublicKeyToken, Version")

      For Each assem As [Assembly] In AppDomain.CurrentDomain.GetAssemblies()
         Console.WriteLine(assem.FullName)
      Next 
   End Sub 
End Class

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8
Show:
© 2015 Microsoft