This documentation is archived and is not being maintained.

CannotUnloadAppDomainException Constructor (SerializationInfo, StreamingContext)

.NET Framework 1.1

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

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

Parameters

info
The object that holds the serialized object data.
context
The contextual information about the source or destination.

Remarks

This constructor is called during deserialization to reconstitute the exception object transmitted over a stream. For more information, see XML and SOAP Serialization.

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

See Also

CannotUnloadAppDomainException Class | CannotUnloadAppDomainException Members | System Namespace | CannotUnloadAppDomainException Constructor Overload List | XML and SOAP Serialization

Show: