18 [__DynamicallyInvokable]
21 private string m_debugString;
26 private Type m_typeOfPermissionThatFailed;
28 private string m_permissionThatFailed;
30 private string m_demanded;
32 private string m_granted;
34 private string m_refused;
36 private string m_denied;
38 private string m_permitOnly;
42 private byte[] m_serializedMethodInfo;
44 private string m_strMethodInfo;
50 private const string ActionName =
"Action";
52 private const string FirstPermissionThatFailedName =
"FirstPermissionThatFailed";
54 private const string DemandedName =
"Demanded";
56 private const string GrantedSetName =
"GrantedSet";
58 private const string RefusedSetName =
"RefusedSet";
60 private const string DeniedName =
"Denied";
62 private const string PermitOnlyName =
"PermitOnly";
64 private const string Assembly_Name =
"Assembly";
66 private const string MethodName_Serialized =
"Method";
68 private const string MethodName_String =
"Method_String";
70 private const string ZoneName =
"Zone";
72 private const string UrlName =
"Url";
91 public Type PermissionType
93 [SecuritySafeCritical]
96 if (m_typeOfPermissionThatFailed ==
null)
98 object obj = XMLUtil.XmlStringToSecurityObject(m_permissionThatFailed);
101 obj = XMLUtil.XmlStringToSecurityObject(m_demanded);
105 m_typeOfPermissionThatFailed = obj.GetType();
108 return m_typeOfPermissionThatFailed;
112 m_typeOfPermissionThatFailed = value;
120 [SecuritySafeCritical]
124 return (
IPermission)XMLUtil.XmlStringToSecurityObject(m_permissionThatFailed);
128 m_permissionThatFailed = XMLUtil.SecurityObjectToXmlString(value);
136 [SecuritySafeCritical]
153 [SecuritySafeCritical]
157 return XMLUtil.XmlStringToSecurityObject(m_demanded);
161 m_demanded = XMLUtil.SecurityObjectToXmlString(value);
169 [SecuritySafeCritical]
185 [SecuritySafeCritical]
202 [SecuritySafeCritical]
206 return XMLUtil.XmlStringToSecurityObject(m_denied);
210 m_denied = XMLUtil.SecurityObjectToXmlString(value);
219 [SecuritySafeCritical]
223 return XMLUtil.XmlStringToSecurityObject(m_permitOnly);
227 m_permitOnly = XMLUtil.SecurityObjectToXmlString(value);
236 [SecuritySafeCritical]
240 return m_assemblyName;
244 m_assemblyName = value;
253 [SecuritySafeCritical]
261 RuntimeMethodInfo runtimeMethodInfo = value as RuntimeMethodInfo;
262 m_serializedMethodInfo = ObjectToByteArray(runtimeMethodInfo);
263 if (runtimeMethodInfo !=
null)
265 m_strMethodInfo = runtimeMethodInfo.ToString();
288 [SecuritySafeCritical]
300 [SecuritySafeCritical]
301 internal static string GetResString(
string sResourceName)
304 return Environment.GetResourceString(sResourceName);
308 internal static Exception MakeSecurityException(
AssemblyName asmName,
Evidence asmEvidence, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh,
SecurityAction action,
object demand, IPermission permThatFailed)
310 HostProtectionPermission hostProtectionPermission = permThatFailed as HostProtectionPermission;
311 if (hostProtectionPermission !=
null)
313 return new HostProtectionException(GetResString(
"HostProtection_HostProtection"), HostProtectionPermission.protectedResources, hostProtectionPermission.Resources);
319 message = ((granted ==
null && refused ==
null && demand ==
null) ? GetResString(
"Security_NoAPTCA") : ((demand !=
null && demand is IPermission) ?
string.Format(
CultureInfo.
InvariantCulture, GetResString(
"Security_Generic"), demand.GetType().AssemblyQualifiedName) : ((permThatFailed ==
null) ? GetResString(
"Security_GenericNoType") : string.Format(
CultureInfo.InvariantCulture, GetResString(
"Security_Generic"), permThatFailed.
GetType().AssemblyQualifiedName))));
320 method = SecurityRuntime.GetMethodInfo(rmh);
329 return new SecurityException(message, asmName, granted, refused, method, action, demand, permThatFailed, asmEvidence);
332 private static byte[] ObjectToByteArray(
object obj)
342 binaryFormatter.
Serialize(memoryStream, obj);
345 catch (NotSupportedException)
351 private static object ByteArrayToObject(
byte[] array)
353 if (array ==
null || array.Length == 0)
359 return binaryFormatter.
Deserialize(serializationStream);
363 [__DynamicallyInvokable]
365 : base(GetResString(
"Arg_SecurityException"))
367 SetErrorCode(-2146233078);
372 [__DynamicallyInvokable]
376 SetErrorCode(-2146233078);
382 [SecuritySafeCritical]
387 SetErrorCode(-2146233078);
388 m_typeOfPermissionThatFailed = type;
395 [SecuritySafeCritical]
400 SetErrorCode(-2146233078);
401 m_typeOfPermissionThatFailed = type;
408 [__DynamicallyInvokable]
410 : base(message, inner)
412 SetErrorCode(-2146233078);
417 : base(GetResString(
"Arg_SecurityException"))
420 SetErrorCode(-2146233078);
421 if (grantedSetObj !=
null)
423 m_granted = grantedSetObj.ToXml().
ToString();
425 if (refusedSetObj !=
null)
427 m_refused = refusedSetObj.ToXml().
ToString();
432 internal SecurityException(
string message, PermissionSet grantedSetObj, PermissionSet refusedSetObj)
435 PermissionSet.s_fullTrust.Assert();
436 SetErrorCode(-2146233078);
437 if (grantedSetObj !=
null)
439 m_granted = grantedSetObj.ToXml().ToString();
441 if (refusedSetObj !=
null)
443 m_refused = refusedSetObj.ToXml().ToString();
452 [SecuritySafeCritical]
454 : base(info, context)
463 m_permissionThatFailed = (string)info.GetValueNoThrow(
"FirstPermissionThatFailed", typeof(
string));
464 m_demanded = (string)info.GetValueNoThrow(
"Demanded", typeof(
string));
465 m_granted = (string)info.GetValueNoThrow(
"GrantedSet", typeof(
string));
466 m_refused = (string)info.GetValueNoThrow(
"RefusedSet", typeof(
string));
467 m_denied = (string)info.GetValueNoThrow(
"Denied", typeof(
string));
468 m_permitOnly = (string)info.GetValueNoThrow(
"PermitOnly", typeof(
string));
470 m_serializedMethodInfo = (
byte[])info.GetValueNoThrow(
"Method", typeof(
byte[]));
471 m_strMethodInfo = (string)info.GetValueNoThrow(
"Method_String", typeof(
string));
473 m_url = (string)info.GetValueNoThrow(
"Url", typeof(
string));
478 m_permissionThatFailed =
"";
484 m_assemblyName =
null;
485 m_serializedMethodInfo =
null;
486 m_strMethodInfo =
null;
502 [SecuritySafeCritical]
507 SetErrorCode(-2146233078);
509 if (permThatFailed !=
null)
511 m_typeOfPermissionThatFailed = permThatFailed.GetType();
515 m_granted = ((grant ==
null) ?
"" : grant.ToXml().
ToString());
516 m_refused = ((refused ==
null) ?
"" : refused.ToXml().
ToString());
519 m_assemblyName = assemblyName;
523 if (evidence !=
null)
525 Url hostEvidence = evidence.GetHostEvidence<
Url>();
526 if (hostEvidence !=
null)
528 m_url = hostEvidence.GetURLString().ToString();
530 Zone hostEvidence2 = evidence.GetHostEvidence<
Zone>();
531 if (hostEvidence2 !=
null)
536 m_debugString =
ToString(includeSensitiveInfo:
true, includeBaseInfo:
false);
546 [SecuritySafeCritical]
551 SetErrorCode(-2146233078);
553 if (permThatFailed !=
null)
555 m_typeOfPermissionThatFailed = permThatFailed.GetType();
563 m_assemblyName =
null;
567 m_debugString =
ToString(includeSensitiveInfo:
true, includeBaseInfo:
false);
572 return (
MethodInfo)ByteArrayToObject(m_serializedMethodInfo);
575 private void ToStringHelper(
StringBuilder sb,
string resourceString,
object attr)
579 string text = attr as string;
582 text = attr.ToString();
584 if (text.Length != 0)
586 sb.
Append(Environment.NewLine);
587 sb.
Append(GetResString(resourceString));
588 sb.
Append(Environment.NewLine);
595 private string ToString(
bool includeSensitiveInfo,
bool includeBaseInfo)
597 PermissionSet.s_fullTrust.Assert();
601 stringBuilder.
Append(base.ToString());
605 ToStringHelper(stringBuilder,
"Security_Action",
Action);
607 ToStringHelper(stringBuilder,
"Security_TypeFirstPermThatFailed",
PermissionType);
608 if (includeSensitiveInfo)
610 ToStringHelper(stringBuilder,
"Security_FirstPermThatFailed", m_permissionThatFailed);
611 ToStringHelper(stringBuilder,
"Security_Demanded", m_demanded);
612 ToStringHelper(stringBuilder,
"Security_GrantedSet", m_granted);
613 ToStringHelper(stringBuilder,
"Security_RefusedSet", m_refused);
614 ToStringHelper(stringBuilder,
"Security_Denied", m_denied);
615 ToStringHelper(stringBuilder,
"Security_PermitOnly", m_permitOnly);
616 ToStringHelper(stringBuilder,
"Security_Assembly", m_assemblyName);
617 ToStringHelper(stringBuilder,
"Security_Method", m_strMethodInfo);
621 ToStringHelper(stringBuilder,
"Security_Zone", m_zone);
623 if (includeSensitiveInfo)
625 ToStringHelper(stringBuilder,
"Security_Url", m_url);
631 private bool CanAccessSensitiveInfo()
648 [SecuritySafeCritical]
649 [__DynamicallyInvokable]
652 return ToString(CanAccessSensitiveInfo(), includeBaseInfo:
true);
666 base.GetObjectData(info, context);
668 info.AddValue(
"FirstPermissionThatFailed", m_permissionThatFailed, typeof(
string));
669 info.AddValue(
"Demanded", m_demanded, typeof(
string));
670 info.AddValue(
"GrantedSet", m_granted, typeof(
string));
671 info.AddValue(
"RefusedSet", m_refused, typeof(
string));
672 info.AddValue(
"Denied", m_denied, typeof(
string));
673 info.AddValue(
"PermitOnly", m_permitOnly, typeof(
string));
674 info.AddValue(
"Assembly", m_assemblyName, typeof(
AssemblyName));
675 info.AddValue(
"Method", m_serializedMethodInfo, typeof(
byte[]));
676 info.AddValue(
"Method_String", m_strMethodInfo, typeof(
string));
678 info.AddValue(
"Url", m_url, typeof(
string));
SecurityException(string message, Type type, string state)
Initializes a new instance of the T:System.Security.SecurityException class with a specified error me...
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
AssemblyName FailedAssemblyInfo
Gets or sets information about the failed assembly.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
object Demanded
Gets or sets the demanded security permission, permission set, or permission set collection that fail...
object PermitOnlySetInstance
Gets or sets the permission, permission set, or permission set collection that is part of the permit-...
SecurityZone
Defines the integer values corresponding to security zones used by security policy.
Discovers the attributes of a method and provides access to method metadata.
Serves as the base class for system exceptions namespace.
Provides the security zone of a code assembly as evidence for policy evaluation. This class cannot be...
SecurityException(string message, Exception inner)
Initializes a new instance of the T:System.Security.SecurityException class with a specified error me...
string RefusedSet
Gets or sets the refused permission set of the assembly that caused the T:System.Security....
SecurityException(string message, AssemblyName assemblyName, PermissionSet grant, PermissionSet refused, MethodInfo method, SecurityAction action, object demanded, IPermission permThatFailed, Evidence evidence)
Initializes a new instance of the T:System.Security.SecurityException class for an exception caused b...
new Type GetType()
Gets the runtime type of the current instance.
object DenySetInstance
Gets or sets the denied security permission, permission set, or permission set collection that caused...
SecurityException()
Initializes a new instance of the T:System.Security.SecurityException class with default properties.
Provides the URL from which a code assembly originates as evidence for policy evaluation....
Describes the source and destination of a given serialized stream, and provides an additional caller-...
SecurityAction Action
Gets or sets the security action that caused the exception.
SecurityAction
Specifies the security actions that can be performed using declarative security.
string GrantedSet
Gets or sets the granted permission set of the assembly that caused the T:System.Security....
Provides information about, and means to manipulate, the current environment and platform....
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
Represents a collection that can contain many different types of permissions.
virtual byte [] ToArray()
Writes the stream contents to a byte array, regardless of the P:System.IO.MemoryStream....
MethodInfo Method
Gets or sets the information about the method associated with the exception.
SecurityException(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.Security.SecurityException class with serialized data.
Represents type declarations: class types, interface types, array types, value types,...
IPermission FirstPermissionThatFailed
Gets or sets the first permission in a permission set or permission set collection that failed the de...
SecurityException(string message)
Initializes a new instance of the T:System.Security.SecurityException class with a specified error me...
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Defines methods implemented by permission types.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
Describes an assembly's unique identity in full.
Exception()
Initializes a new instance of the T:System.Exception class.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
override void GetObjectData(SerializationInfo info, StreamingContext context)
Sets the T:System.Runtime.Serialization.SerializationInfo with information about the T:System....
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Defines the set of information that constitutes input to security policy decisions....
Specifies that the class can be serialized.
override string ToString()
Returns a representation of the current T:System.Security.SecurityException.
Type PermissionType
Gets or sets the type of the permission that failed.
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
Provides information about a specific culture (called a locale for unmanaged code development)....
SecurityZone SecurityZone
Gets the zone from which the code assembly originates.
SecurityPermissionFlag
Specifies access flags for the security permission object.
The exception that is thrown when a call is made to the M:System.Threading.Thread....
The exception that is thrown when a security error is detected.
override string ToString()
Produces a string representation of an XML element and its constituent attributes,...
SecurityException(string message, object deny, object permitOnly, MethodInfo method, object demanded, IPermission permThatFailed)
Initializes a new instance of the T:System.Security.SecurityException class for an exception caused b...
SecurityException(string message, Type type)
Initializes a new instance of the T:System.Security.SecurityException class with a specified error me...