Export (0) Print
Expand All

CannotUnloadAppDomainException Constructor (String)

.NET Framework 1.1

Initializes a new instance of the CannotUnloadAppDomainException class with a specified error message.

[Visual Basic]
Public Sub New( _
   ByVal message As String _
)
[C#]
public CannotUnloadAppDomainException(
   string message
);
[C++]
public: CannotUnloadAppDomainException(
   String* message
);
[JScript]
public function CannotUnloadAppDomainException(
   message : String
);

Parameters

message
A String that describes the error.

Remarks

The content of the message parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

The following table shows the initial property values for an instance of CannotUnloadAppDomainException.

Property Value
InnerException A null reference (Nothing in Visual Basic).
Message The error message string.

Example

[Visual Basic] 
Imports System
Imports System.Reflection
Imports System.Security.Policy
 '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 = "file:///" + 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 new the application domain.
      newDomain.Load("System.data, version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
      
      'Unload the application domain, which also unloads the assembly.
      AppDomain.Unload(newDomain)
      
      Try
         AppDomain.Unload(newDomain)
      Catch e As CannotUnloadAppDomainException
         Console.WriteLine("System can't unload appdomain.  " & e.ToString())
      End Try
   End Sub 'Main
End Class 'ADMultiDomain

[C#] 
using System;
using System.Reflection;
using System.Security.Policy;  //for evidence object

class ADMultiDomain
{
    // The following attribute indicates to loader that multiple application 
    // domains are used in this application.
    [LoaderOptimizationAttribute( LoaderOptimization.MultiDomainHost)]
    public static void Main()
    {
        // Create application domain setup information for new application domain.
        AppDomainSetup domaininfo = new AppDomainSetup();
        domaininfo.ApplicationBase = "file:///" + System.Environment.CurrentDirectory;
        domaininfo.ApplicationName = "MyMultiDomain Application";

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

        // Create appdomain.
        AppDomain newDomain = AppDomain.CreateDomain("MyMultiDomain", adevidence, domaininfo);

        //Load an assembly into new the application domain.
        newDomain.Load("System.data, version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

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

        try
        {    
        AppDomain.Unload(newDomain);
        }
        catch (CannotUnloadAppDomainException e)
            {
             Console.WriteLine("System can't unload appdomain.  " + e);
            }
    }
}

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

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

// The following attribute indicates to loader that multiple application
// domains are used in this application.
[LoaderOptimizationAttribute(LoaderOptimization::MultiDomainHost)]
int main() {
   // Create application domain setup information for new application domain.
   AppDomainSetup* domaininfo = new AppDomainSetup();
   domaininfo->ApplicationBase = S"file:////{0}", System::Environment::CurrentDirectory;
   domaininfo->ApplicationName = S"MyMultiDomain Application";

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

   // Create appdomain.
   AppDomain*  newDomain = AppDomain::CreateDomain(S"MyMultiDomain", adevidence, domaininfo);

   //Load an assembly into new the application domain.
   newDomain->Load(S"System.data, version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

   //Unload the application domain, which also unloads the assembly.
   AppDomain::Unload(newDomain);

   try {
      AppDomain::Unload(newDomain);
   } catch (CannotUnloadAppDomainException* e) {
      Console::WriteLine(S"System can't unload appdomain. {0}", e);
   }
}

[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, Common Language Infrastructure (CLI) Standard

See Also

CannotUnloadAppDomainException Class | CannotUnloadAppDomainException Members | System Namespace | CannotUnloadAppDomainException Constructor Overload List

Show:
© 2014 Microsoft