[Serializable]
#if NET_2_0
- public class SecurityException : SystemException, _Exception {
-#else
- public class SecurityException : SystemException {
+ [ComVisible (true)]
#endif
+ public class SecurityException : SystemException {
// Fields
string permissionState;
Type permissionType;
private string _granted;
private string _refused;
- private SecurityAction _action;
private object _demanded;
+ private IPermission _firstperm;
+// private IPermission _permfailed;
+ private MethodInfo _method;
+ private Evidence _evidence;
+
+#if !NET_2_0
+ #pragma warning disable 169
+#endif
+ private SecurityAction _action;
private object _denyset;
private object _permitset;
private AssemblyName _assembly;
- private IPermission _firstperm;
- private IPermission _permfailed;
- private MethodInfo _method;
private string _url;
private SecurityZone _zone;
+
+#if !NET_2_0
+ #pragma warning restore 169
+#endif
// Properties
set { _method = value; }
}
- [Obsolete]
- [ComVisible (false)]
- public IPermission PermissionThatFailed {
- get { return _permfailed; }
- set { _permfailed = value; }
- }
-
[ComVisible (false)]
public object PermitOnlySetInstance {
[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
: base (info, context)
{
base.HResult = unchecked ((int)0x8013150A);
- permissionState = info.GetString ("PermissionState");
+ // depending on the security policy the info about PermissionState may
+ // not be available (but the serializable must work)
+ SerializationInfoEnumerator e = info.GetEnumerator ();
+ while (e.MoveNext ()) {
+ if (e.Name == "PermissionState") {
+ permissionState = (string) e.Value;
+ break;
+ }
+ }
}
public SecurityException (string message, Exception inner)
_firstperm = permThatFailed;
if (_firstperm != null)
permissionType = _firstperm.GetType ();
- // FIXME ? evidence ?
+ _evidence = evidence;
}
// Methods
public override void GetObjectData (SerializationInfo info, StreamingContext context)
{
base.GetObjectData (info, context);
- info.AddValue ("PermissionState", permissionState);
+ try {
+ info.AddValue ("PermissionState", PermissionState);
+ }
+ catch (SecurityException) {
+ // serialize only if permitted to do so
+ }
}
public override string ToString ()
{
+#if NET_2_1
+ return base.ToString ();
+#else
StringBuilder sb = new StringBuilder (base.ToString ());
try {
+ if (permissionType != null) {
+ sb.AppendFormat ("{0}Type: {1}", Environment.NewLine, PermissionType);
+ }
if (_method != null) {
// method string representation doesn't include the type
string m = _method.ToString ();
if (permissionState != null) {
sb.AppendFormat ("{0}State: {1}", Environment.NewLine, PermissionState);
}
- if (permissionType != null) {
- sb.AppendFormat ("{0}Type: {1}", Environment.NewLine, PermissionType);
- }
if ((_granted != null) && (_granted.Length > 0)) {
sb.AppendFormat ("{0}Granted: {1}", Environment.NewLine, GrantedSet);
}
if (_firstperm != null) {
sb.AppendFormat ("{0}Failed Permission: {1}", Environment.NewLine, FirstPermissionThatFailed);
}
+ if (_evidence != null) {
+ sb.AppendFormat ("{0}Evidences:", Environment.NewLine);
+ foreach (object o in _evidence) {
+ // Hash evidence is way much too verbose to be useful to anyone
+ if (!(o is Hash))
+ sb.AppendFormat ("{0}\t{1}", Environment.NewLine, o);
+ }
+ }
}
catch (SecurityException) {
// some informations can't be displayed
}
return sb.ToString ();
+#endif
}
}
}