11
.NET Framework Supported in: 4, 3.5, 3.0, 2.0 .NET Framework Client Profile Supported in: 4, 3.5 SP1 .NET Framework Security SecurityCriticalAttribute Requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. SecurityAction.InheritanceDemand for derived classes to plug executable code into the common language runtime hosting infrastructure. Associated enumeration: SecurityPermissionFlag.Infrastructure. .NET Framework 4 Represents assembly binding information that can be added to an instance of AppDomain. Inheritance Hierarchy System.Object System.AppDomainSetup Namespace: System Assembly: mscorlib (in mscorlib.dll) Syntax C#

Clases Net II

Embed Size (px)

DESCRIPTION

tratado de clases ii

Citation preview

Page 1: Clases Net II

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET Framework Security

SecurityCriticalAttribute

Requires full trust for the immediate caller. This member cannot be used bypartially trusted or transparent code.

SecurityAction.InheritanceDemand

for derived classes to plug executable code into the common language runtimehosting infrastructure. Associated enumeration:SecurityPermissionFlag.Infrastructure.

.NET Framework 4

Represents assembly binding information that can be added to an instance of AppDomain.

Inheritance Hierarchy

System.Object

System.AppDomainSetup

Namespace: System

Assembly: mscorlib (in mscorlib.dll)

Syntax

C#

Page 2: Clases Net II

[SerializableAttribute][ComVisibleAttribute(true)][ClassInterfaceAttribute(ClassInterfaceType.None)]public sealed class AppDomainSetup : IAppDomainSetup

The AppDomainSetup type exposes the following members.

Constructors

Show: Inherited Protected

Name Description

AppDomainSetup() Initializes a new instance of the AppDomainSetup class.

AppDomainSetup(ActivationArguments)

Initializes a new instance of the AppDomainSetup class

with the specified activation arguments required for

manifest-based activation of an application domain.

AppDomainSetup(ActivationContext)

Initializes a new instance of the AppDomainSetup class

with the specified activation context to use for manifest-

based activation of an application domain.

Properties

Show: Inherited Protected

Name Description

ActivationArguments Gets or sets data about the activation of an application domain.

AppDomainInitializer

Gets or sets the AppDomainInitializer delegate, which

represents a callback method that is invoked when the

application domain is initialized.

AppDomainInitializerArguments

Gets or sets the arguments passed to the callback method

represented by the AppDomainInitializer delegate. The callback

method is invoked when the application domain is initialized.

AppDomainManagerAssembly Gets or sets the display name of the assembly that provides the

type of the application domain manager for application domains

Page 3: Clases Net II

created using this AppDomainSetup object.

AppDomainManagerType

Gets or sets the full name of the type that provides the

application domain manager for application domains created

using this AppDomainSetup object.

ApplicationBaseGets or sets the name of the directory containing the

application.

ApplicationName Gets or sets the name of the application.

ApplicationTrust Gets or sets an object containing security and trust information.

CachePathGets or sets the name of an area specific to the application

where files are shadow copied.

ConfigurationFileGets or sets the name of the configuration file for an application

domain.

DisallowApplicationBaseProbingSpecifies whether the application base path and private binary

path are probed when searching for assemblies to load.

DisallowBindingRedirectsGets or sets a value that indicates whether an application

domain allows assembly binding redirection.

DisallowCodeDownloadGets or sets a value that indicates whether HTTP download of

assemblies is allowed for an application domain.

DisallowPublisherPolicy

Gets or sets a value that indicates whether the

<publisherPolicy> section of the configuration file is applied to

an application domain.

DynamicBaseGets or sets the base directory where the directory for

dynamically generated files is located.

LicenseFileGets or sets the location of the license file associated with this

domain.

LoaderOptimization Specifies the optimization policy used to load an executable.

PartialTrustVisibleAssemblies

Gets or sets a list of assemblies marked with the

NotVisibleByDefault flag that are made visible to partial-trust

code running in a sandboxed application domain.

Page 4: Clases Net II

PrivateBinPathGets or sets the list of directories under the application base

directory that are probed for private assemblies.

PrivateBinPathProbe

Gets or sets a string value that includes or excludes

ApplicationBase from the search path for the application, and

searches only PrivateBinPath.

SandboxInterop

Gets or sets a value that indicates whether interface caching is

disabled for interop calls in the application domain, so that a

QueryInterface is performed on each call.

ShadowCopyDirectoriesGets or sets the names of the directories containing assemblies

to be shadow copied.

ShadowCopyFilesGets or sets a string that indicates whether shadow copying is

turned on or off.

Methods

Show: Inherited Protected

Name Description

Equals(Object)Determines whether the specified Object is equal to the current

Object. (Inherited from Object.)

Finalize

Allows an object to try to free resources and perform other cleanup

operations before it is reclaimed by garbage collection. (Inherited from

Object.)

GetConfigurationBytes

Returns the XML configuration information set by the

SetConfigurationBytes method, which overrides the application's XML

configuration information.

GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)

GetType Gets the Type of the current instance. (Inherited from Object.)

MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)

SetCompatibilitySwitches Sets the specified switches, making the application domain compatible

Page 5: Clases Net II

with previous versions of the .NET Framework for the specified issues.

SetConfigurationBytesProvides XML configuration information for the application domain,

replacing the application's XML configuration information.

ToStringReturns a string that represents the current object. (Inherited from

Object.)

Remarks

Changing the properties of an AppDomainSetup instance does not affect any existingAppDomain. It can affect only the creation of a new AppDomain, when the CreateDomainmethod is called with the AppDomainSetup instance as a parameter.

This class implements the IAppDomainSetup interface.

Caution

The default value for the DisallowCodeDownload property is false. This setting is unsafefor services. To help prevent services from downloading partially trusted code, set thisproperty to true

Topic Location

How to: Configure an Application Domain .NET Framework: Programming Fundamentals

How to: Configure an Application Domain .NET Framework: Programming Fundamentals

How to: Configure an Application Domain

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Page 6: Clases Net II

.NET Framework 4

The exception that is thrown when an attempt is made to access an unloaded applicationdomain.

Inheritance Hierarchy

System.Object

System.Exception

System.SystemException

System.AppDomainUnloadedException

Namespace: System

Assembly: mscorlib (in mscorlib.dll)

Syntax

C#

[SerializableAttribute][ComVisibleAttribute(true)]public class AppDomainUnloadedException : SystemException

The AppDomainUnloadedException type exposes the following members.

Constructors

Show: Inherited Protected

Name Description

AppDomainUnloadedException()Initializes a new instance of the

AppDomainUnloadedException class.

AppDomainUnloadedException(String)

Initializes a new instance of the

AppDomainUnloadedException class with a

specified error message.

Page 7: Clases Net II

AppDomainUnloadedException(SerializationInfo,

StreamingContext)

Initializes a new instance of the

AppDomainUnloadedException class with

serialized data.

AppDomainUnloadedException(String, Exception)

Initializes a new instance of the

AppDomainUnloadedException class with a

specified error message and a reference to

the inner exception that is the cause of this

exception.

Properties

Show: Inherited Protected

Name Description

DataGets a collection of key/value pairs that provide additional user-defined

information about the exception. (Inherited from Exception.)

HelpLinkGets or sets a link to the help file associated with this exception. (Inherited from

Exception.)

HResultGets or sets HRESULT, a coded numerical value that is assigned to a specific

exception. (Inherited from Exception.)

InnerExceptionGets the Exception instance that caused the current exception. (Inherited from

Exception.)

Message Gets a message that describes the current exception. (Inherited from Exception.)

SourceGets or sets the name of the application or the object that causes the error.

(Inherited from Exception.)

StackTraceGets a string representation of the immediate frames on the call stack. (Inherited

from Exception.)

TargetSite Gets the method that throws the current exception. (Inherited from Exception.)

Methods

Page 8: Clases Net II

Show: Inherited Protected

Name Description

Equals(Object)Determines whether the specified Object is equal to the current Object.

(Inherited from Object.)

Finalize

Allows an object to try to free resources and perform other cleanup

operations before it is reclaimed by garbage collection. (Inherited from

Object.)

GetBaseExceptionWhen overridden in a derived class, returns the Exception that is the root

cause of one or more subsequent exceptions. (Inherited from Exception.)

GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)

GetObjectDataWhen overridden in a derived class, sets the SerializationInfo with

information about the exception. (Inherited from Exception.)

GetType

Gets the runtime type of the current instance. (Inherited from Exception.)

In XNA Framework 3.0, this member is inherited from Object.GetType().

MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)

ToStringCreates and returns a string representation of the current exception.

(Inherited from Exception.)

Events

Show: Inherited Protected

Name Description

SerializeObjectState

Occurs when an exception is serialized to create an exception state object

that contains serialized data about the exception. (Inherited from

Exception.)

Remarks

Page 9: Clases Net II

In the .NET Framework version 2.0, an AppDomainUnloadedException that is not handledin user code has the following effect:

If a thread was started in managed code, it is terminated. The unhandled exceptionis not allowed to terminate the application.If a task is executing on a ThreadPool thread, it is terminated and the thread isreturned to the thread pool. The unhandled exception is not allowed to terminate theapplication.If a thread started in unmanaged code, such as the main application thread, it isterminated. The unhandled exception is allowed to proceed, and the operatingsystem terminates the application.

AppDomainUnloadedException uses the HRESULT COR_E_APPDOMAINUNLOADED,which has the value 0x80131014.

For a list of initial property values for an instance of AppDomainUnloadedException, seethe AppDomainUnloadedException constructors.

Examples

This section contains two code examples. The first example demonstrates the effects of anAppDomainUnloadedException on various threads, and the second shows elementaryapplication domain unloading.

Example 1

The following code example defines a TestClass class that can be marshaled acrossapplication domain boundaries and an Example class containing a static (Shared in VisualBasic) ThreadProc method. The ThreadProc method creates an application domain, createsa TestClass object in the domain, and calls a method of TestClass that unloads theexecuting domain, causing an AppDomainUnloadedException.

The TestClass method is executed without exception handling from a ThreadPool threadand from an ordinary thread, demonstrating that the unhandled exception terminates thetask or thread but not the application. It is then executed with and without exceptionhandling from the main application thread, demonstrating that it terminates the applicationif not handled.

C#

using System;using System.Threading;using System.Runtime.InteropServices;

public class Example{

Page 10: Clases Net II

public static void Main(){

// 1. Queue ThreadProc as a task for a ThreadPool thread.ThreadPool.QueueUserWorkItem(ThreadProc, " from a ThreadPool

thread");Thread.Sleep(1000);

// 2. Execute ThreadProc on an ordinary thread.Thread t = new Thread(ThreadProc);t.Start(" from an ordinary thread");t.Join();

// 3. Execute ThreadProc on the main thread, with// exception handling.try{

ThreadProc(" from the main application thread (handled)");}catch (AppDomainUnloadedException adue){

Console.WriteLine("Main thread caughtAppDomainUnloadedException: {0}", adue.Message);

}

// 4. Execute ThreadProc on the main thread without// exception handling.ThreadProc(" from the main application thread (unhandled)");

Console.WriteLine("Main: This message is never displayed.");}

private static void ThreadProc(object state){

// Create an application domain, and create an instance// of TestClass in the application domain. The first// parameter of CreateInstanceAndUnwrap is the name of// this executable. If you compile the example code using// any name other than "Sample.exe", you must change the// parameter appropriately.AppDomain ad = AppDomain.CreateDomain("TestDomain");TestClass tc = (TestClass)ad.CreateInstanceAndUnwrap("Sample",

"TestClass");

// In the new application domain, execute a method that// unloads the AppDomain. The unhandled exception this// causes ends the current thread.tc.UnloadCurrentDomain(state);

Console.WriteLine("ThreadProc: This message is neverdisplayed.");

}}

// TestClass derives from MarshalByRefObject, so it can be marshaled// across application domain boundaries.//public class TestClass : MarshalByRefObject

Page 11: Clases Net II

{public void UnloadCurrentDomain(object state){

Console.WriteLine("\nUnloading the current AppDomain{0}.",state);

// Unload the current application domain. This causes// an AppDomainUnloadedException to be thrown.//AppDomain.Unload(AppDomain.CurrentDomain);

}}

/* This code example produces output similar to the following:Unloading the current AppDomain from a ThreadPool thread.

Unloading the current AppDomain from an ordinary thread.

Unloading the current AppDomain from the main application thread(handled).Main thread caught AppDomainUnloadedException: The application domain inwhich the thread was running has been unloaded.

Unloading the current AppDomain from the main application thread(unhandled).

Unhandled Exception: System.AppDomainUnloadedException: The applicationdomain in which the thread was running has been unloaded.

at TestClass.UnloadCurrentDomain(Object state)at Example.ThreadProc(Object state)at Example.Main()

*/

Example 2

The following code example creates and unloads an application domain, and demonstratesthat an AppDomainUnloadedException is thrown on a subsequent attempt to access theunloaded domain.

C#

using System;using System.Reflection;using System.Security.Policy; //for evidence objectclass ADUnload{

public static void Main(){

//Create evidence for the new appdomain.Evidence adevidence = AppDomain.CurrentDomain.Evidence;

// Create the new application domain.