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

CannotUnloadAppDomainException Constructor

.NET Framework 1.1

Initializes a new instance of the CannotUnloadAppDomainException class.

Overload List

Initializes a new instance of the CannotUnloadAppDomainException class.

[Visual Basic] Public Sub New()
[C#] public CannotUnloadAppDomainException();
[C++] public: CannotUnloadAppDomainException();
[JScript] public function CannotUnloadAppDomainException();

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

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

Initializes a new instance of the CannotUnloadAppDomainException class from serialized data.

[Visual Basic] Protected Sub New(SerializationInfo, StreamingContext)
[C#] protected CannotUnloadAppDomainException(SerializationInfo, StreamingContext);
[C++] protected: CannotUnloadAppDomainException(SerializationInfo*, StreamingContext);
[JScript] protected function CannotUnloadAppDomainException(SerializationInfo, StreamingContext);

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(String, Exception)
[C#] public CannotUnloadAppDomainException(string, Exception);
[C++] public: CannotUnloadAppDomainException(String*, Exception*);
[JScript] public function CannotUnloadAppDomainException(String, Exception);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the CannotUnloadAppDomainException constructor. For other examples that might be available, see the individual overload topics.
[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.

See Also

CannotUnloadAppDomainException Class | CannotUnloadAppDomainException Members | System Namespace

Show:
© 2015 Microsoft