Export (0) Print
Expand All

CannotUnloadAppDomainException Constructor (String, Exception)

.NET Framework 1.1

Initializes a new instance of the CannotUnloadAppDomainException class with a specified error message and a reference to the inner exception that is the cause of this exception.

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

Parameters

message
The error message that explains the reason for the exception.
innerException
The exception that is the cause of the current exception. If the innerException parameter is not a null reference (Nothing in Visual Basic), the current exception is raised in a catch block that handles the inner exception.

Remarks

An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the InnerException property. The InnerException property returns the same value that is passed into the constructor, or a null reference (Nothing in Visual Basic) if the InnerException property does not supply the inner exception value to the constructor.

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

Property Value
InnerException The inner exception reference.
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 | Exception | Handling and Throwing Exceptions

Show:
© 2014 Microsoft