SecurityException Constructors

Definition

Initializes a new instance of the SecurityException class.

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)
Obsolete.

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();
public SecurityException ();
Public Sub New ()

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.

Applies to

SecurityException(String)

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

public:
 SecurityException(System::String ^ message);
public SecurityException (string message);
public SecurityException (string? message);
new System.Security.SecurityException : string -> System.Security.SecurityException
Public Sub New (message As String)

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.

Applies to

SecurityException(SerializationInfo, StreamingContext)

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

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

protected:
 SecurityException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected SecurityException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected SecurityException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Security.SecurityException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.SecurityException
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.SecurityException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.SecurityException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parameters

info
SerializationInfo

The object that holds the serialized object data.

context
StreamingContext

The contextual information about the source or destination.

Attributes

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:

Applies to

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(System::String ^ message, Exception ^ inner);
public SecurityException (string message, Exception inner);
public SecurityException (string? message, Exception? inner);
new System.Security.SecurityException : string * Exception -> System.Security.SecurityException
Public Sub New (message As String, inner As Exception)

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

Applies to

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(System::String ^ message, Type ^ type);
public SecurityException (string? message, Type? type);
public SecurityException (string message, Type type);
new System.Security.SecurityException : string * Type -> System.Security.SecurityException
Public Sub New (message As String, type As 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.

Applies to

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(System::String ^ message, Type ^ type, System::String ^ state);
public SecurityException (string? message, Type? type, string? state);
public SecurityException (string message, Type type, string state);
new System.Security.SecurityException : string * Type * string -> System.Security.SecurityException
Public Sub New (message As String, type As Type, state As String)

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.

Applies to

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(System::String ^ message, System::Object ^ deny, System::Object ^ permitOnly, System::Reflection::MethodInfo ^ method, System::Object ^ demanded, System::Security::IPermission ^ permThatFailed);
public SecurityException (string message, object deny, object permitOnly, System.Reflection.MethodInfo method, object demanded, System.Security.IPermission permThatFailed);
new System.Security.SecurityException : string * obj * obj * System.Reflection.MethodInfo * obj * System.Security.IPermission -> System.Security.SecurityException
Public Sub New (message As String, deny As Object, permitOnly As Object, method As MethodInfo, demanded As Object, permThatFailed As IPermission)

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.

Applies to

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(System::String ^ message, System::Reflection::AssemblyName ^ assemblyName, System::Security::PermissionSet ^ grant, System::Security::PermissionSet ^ refused, System::Reflection::MethodInfo ^ method, System::Security::Permissions::SecurityAction action, System::Object ^ demanded, System::Security::IPermission ^ permThatFailed, System::Security::Policy::Evidence ^ evidence);
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);
new System.Security.SecurityException : string * System.Reflection.AssemblyName * System.Security.PermissionSet * System.Security.PermissionSet * System.Reflection.MethodInfo * System.Security.Permissions.SecurityAction * obj * System.Security.IPermission * System.Security.Policy.Evidence -> System.Security.SecurityException
Public Sub New (message As String, assemblyName As AssemblyName, grant As PermissionSet, refused As PermissionSet, method As MethodInfo, action As SecurityAction, demanded As Object, permThatFailed As IPermission, evidence As 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