SecurityException Constructors

Definition

Overloads

SecurityException()

Initializes a new instance of the SecurityException class with default properties.

SecurityException(String)

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

SecurityException(SerializationInfo, StreamingContext)

Initializes a new instance of the SecurityException class with serialized data.

SecurityException(String, Exception)

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

SecurityException(String, Type)

Initializes a new instance of the SecurityException class with a specified error message and the permission type that caused the exception to be thrown.

SecurityException(String, Type, String)

Initializes a new instance of the SecurityException class with a specified error message, the permission type that caused the exception to be thrown, and the permission state.

SecurityException(String, Object, Object, MethodInfo, Object, IPermission)

Initializes a new instance of the SecurityException class for an exception caused by a Deny on the stack.

SecurityException(String, AssemblyName, PermissionSet, PermissionSet, MethodInfo, SecurityAction, Object, IPermission, Evidence)

Initializes a new instance of the SecurityException class for an exception caused by an insufficient grant set.

Examples

For an example of the use of a SecurityException constructor, see the example provided for the SecurityException(String, Object, Object, MethodInfo, Object, IPermission) constructor.

SecurityException()

Initializes a new instance of the SecurityException class with default properties.

public SecurityException ();

Examples

For an example of the use of a SecurityException constructor, see the example provided for the SecurityException(String, Object, Object, MethodInfo, Object, IPermission) constructor.

Remarks

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

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

SecurityException(String)

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

public SecurityException (string message);
Parameters
message
String

The error message that explains the reason for the exception.

Examples

For an example of the use of a SecurityException constructor, see the example provided for the SecurityException(String, Object, Object, MethodInfo, Object, IPermission) constructor.

Remarks

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

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

SecurityException(SerializationInfo, StreamingContext)

Initializes a new instance of the SecurityException class with serialized data.

protected SecurityException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
Parameters
info
SerializationInfo

The object that holds the serialized object data.

context
StreamingContext

The contextual information about the source or destination.

Exceptions

info is null.

Examples

For an example of the use of a SecurityException constructor, see the example provided for the SecurityException(String, Object, Object, MethodInfo, Object, IPermission) constructor.

Remarks

This constructor is called during deserialization to reconstitute the exception object transmitted over a stream.

This constructor sets the following property values based on the information in the info parameter:

SecurityException(String, Exception)

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

public SecurityException (string message, Exception inner);
Parameters
message
String

The error message that explains the reason for the exception.

inner
Exception

The exception that is the cause of the current exception. If the inner parameter is not null, the current exception is raised in a catch block that handles the inner exception.

Examples

For an example of the use of a SecurityException constructor, see the example provided for the SecurityException(String, Object, Object, MethodInfo, Object, IPermission) constructor.

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 null 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 the SecurityException class.

Property Value
InnerException The inner exception reference.
Message The localized error message string.
See Also

SecurityException(String, Type)

Initializes a new instance of the SecurityException class with a specified error message and the permission type that caused the exception to be thrown.

public SecurityException (string message, Type type);
Parameters
message
String

The error message that explains the reason for the exception.

type
Type

The type of the permission that caused the exception to be thrown.

Examples

For an example of the use of a SecurityException constructor, see the example provided for the SecurityException(String, Object, Object, MethodInfo, Object, IPermission) constructor.

Remarks

The following table shows the property values set by this constructor.

Property Value
Message The localized error message string specified by message.
PermissionType The Type of the permission that failed, specified by type.

SecurityException(String, Type, String)

Initializes a new instance of the SecurityException class with a specified error message, the permission type that caused the exception to be thrown, and the permission state.

public SecurityException (string message, Type type, string state);
Parameters
message
String

The error message that explains the reason for the exception.

type
Type

The type of the permission that caused the exception to be thrown.

state
String

The state of the permission that caused the exception to be thrown.

Examples

For an example of the use of a SecurityException constructor, see the example provided for the SecurityException(String, Object, Object, MethodInfo, Object, IPermission) constructor.

Remarks

The following table shows the property values set by this constructor.

Property Value
Message The localized error message string specified by message.
PermissionType The Type of the permission that failed, specified by type.
Demanded The demanded security permission, permission set, or permission set collection that failed.

SecurityException(String, Object, Object, MethodInfo, Object, IPermission)

Initializes a new instance of the SecurityException class for an exception caused by a Deny on the stack.

public SecurityException (string message, object deny, object permitOnly, System.Reflection.MethodInfo method, object demanded, System.Security.IPermission permThatFailed);
Parameters
message
String

The error message that explains the reason for the exception.

deny
Object

The denied permission or permission set.

permitOnly
Object

The permit-only permission or permission set.

method
MethodInfo

A MethodInfo that identifies the method that encountered the exception.

demanded
Object

The demanded permission, permission set, or permission set collection.

permThatFailed
IPermission

An IPermission that identifies the permission that failed.

Examples

The following code example shows the use of the SecurityException(String, Object, Object, MethodInfo, Object, IPermission) constructor.

// Demonstrate the SecurityException constructor
// by throwing the exception again.
Display("Rethrowing the exception thrown as a "
    "result of a PermitOnly security action.");
throw gcnew SecurityException(exception->Message,
    exception->DenySetInstance,
    exception->PermitOnlySetInstance,
    exception->Method, exception->Demanded,
    exception->FirstPermissionThatFailed);
//Demonstrate the SecurityException constructor by 
// throwing the exception again.
Display("Rethrowing the exception thrown as a result of a " + 
    "PermitOnly security action.");
throw new SecurityException(sE.Message, sE.DenySetInstance, 
    sE.PermitOnlySetInstance, sE.Method, sE.Demanded, 
    (IPermission)sE.FirstPermissionThatFailed);
' Demonstrate the SecurityException constructor by 
' throwing the exception again.
Display("Rethrowing the exception thrown as a result of a " & _
    "PermitOnly security action.")
Throw New SecurityException(sE.Message, sE.DenySetInstance, _
    sE.PermitOnlySetInstance, sE.Method, sE.Demanded, _
    CType(sE.FirstPermissionThatFailed, IPermission))

Remarks

Use this constructor if a frame that contains a Deny caused the demand failure. The following table shows the property values set by this constructor.

Property Value
Message The localized error message string specified by message.
FirstPermissionThatFailed The first permission in the permission set or permission set collection specified by permThatFailed.
GrantedSet An empty string.
Demanded The security permission, permission set, or permission set collection specified by demanded.
RefusedSet An empty string.
DenySetInstance The denied security permission, permission set, or permission set collection specified by deny.
PermitOnlySetInstance The permission, permission set, or permission set collection specified by permitOnly.
FailedAssemblyInfo null.
Method The MethodInfo specified by method.
Zone NoZone.
Url An empty string.

SecurityException(String, AssemblyName, PermissionSet, PermissionSet, MethodInfo, SecurityAction, Object, IPermission, Evidence)

Initializes a new instance of the SecurityException class for an exception caused by an insufficient grant set.

public SecurityException (string message, System.Reflection.AssemblyName assemblyName, System.Security.PermissionSet grant, System.Security.PermissionSet refused, System.Reflection.MethodInfo method, System.Security.Permissions.SecurityAction action, object demanded, System.Security.IPermission permThatFailed, System.Security.Policy.Evidence evidence);
Parameters
message
String

The error message that explains the reason for the exception.

assemblyName
AssemblyName

An AssemblyName that specifies the name of the assembly that caused the exception.

grant
PermissionSet

A PermissionSet that represents the permissions granted the assembly.

refused
PermissionSet

A PermissionSet that represents the refused permission or permission set.

method
MethodInfo

A MethodInfo that represents the method that encountered the exception.

action
SecurityAction

One of the SecurityAction values.

demanded
Object

The demanded permission, permission set, or permission set collection.

permThatFailed
IPermission

An IPermission that represents the permission that failed.

evidence
Evidence

The Evidence for the assembly that caused the exception.

Remarks

Use this constructor to throw an exception when the grant set caused the failure of the demand.

The following table shows the property values set by this constructor.

Property Value
Message The localized error message string specified by message.
FirstPermissionThatFailed The first permission in the permission set or permission set collection specified by permThatFailed.
GrantedSet The PermissionSet specified by grant.
Demanded The demanded security permission, permission set, or permission set collection that failed, specified by demanded.
RefusedSet The PermissionSet specified by refused.
DenySetInstance An empty string.
PermitOnlySetInstance An empty string.
FailedAssemblyInfo The AssemblyName specified by assemblyName.
Method The MethodInfo specified by method.
Zone The SecurityZone value from the Evidence specified by evidence.
Url The URL from the Evidence specified by evidence.
See Also

Applies to