SecurityException.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Reflection;
  5. using System.Runtime.Serialization;
  6. namespace System.Security
  7. {
  8. [Serializable]
  9. [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
  10. public class SecurityException : SystemException
  11. {
  12. private const string DemandedName = "Demanded";
  13. private const string GrantedSetName = "GrantedSet";
  14. private const string RefusedSetName = "RefusedSet";
  15. private const string DeniedName = "Denied";
  16. private const string PermitOnlyName = "PermitOnly";
  17. private const string UrlName = "Url";
  18. public SecurityException()
  19. : base(SR.Arg_SecurityException)
  20. {
  21. HResult = HResults.COR_E_SECURITY;
  22. }
  23. public SecurityException(string message)
  24. : base(message)
  25. {
  26. HResult = HResults.COR_E_SECURITY;
  27. }
  28. public SecurityException(string message, Exception inner)
  29. : base(message, inner)
  30. {
  31. HResult = HResults.COR_E_SECURITY;
  32. }
  33. public SecurityException(string message, Type type)
  34. : base(message)
  35. {
  36. HResult = HResults.COR_E_SECURITY;
  37. PermissionType = type;
  38. }
  39. public SecurityException(string message, Type type, string state)
  40. : base(message)
  41. {
  42. HResult = HResults.COR_E_SECURITY;
  43. PermissionType = type;
  44. PermissionState = state;
  45. }
  46. protected SecurityException(SerializationInfo info, StreamingContext context)
  47. : base(info, context)
  48. {
  49. Demanded = (string)info.GetValueNoThrow(DemandedName, typeof(string));
  50. GrantedSet = (string)info.GetValueNoThrow(GrantedSetName, typeof(string));
  51. RefusedSet = (string)info.GetValueNoThrow(RefusedSetName, typeof(string));
  52. DenySetInstance = (string)info.GetValueNoThrow(DeniedName, typeof(string));
  53. PermitOnlySetInstance = (string)info.GetValueNoThrow(PermitOnlyName, typeof(string));
  54. Url = (string)info.GetValueNoThrow(UrlName, typeof(string));
  55. }
  56. public override string ToString() => base.ToString();
  57. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  58. {
  59. base.GetObjectData(info, context);
  60. info.AddValue(DemandedName, Demanded, typeof(string));
  61. info.AddValue(GrantedSetName, GrantedSet, typeof(string));
  62. info.AddValue(RefusedSetName, RefusedSet, typeof(string));
  63. info.AddValue(DeniedName, DenySetInstance, typeof(string));
  64. info.AddValue(PermitOnlyName, PermitOnlySetInstance, typeof(string));
  65. info.AddValue(UrlName, Url, typeof(string));
  66. }
  67. public object Demanded { get; set; }
  68. public object DenySetInstance { get; set; }
  69. public AssemblyName FailedAssemblyInfo { get; set; }
  70. public string GrantedSet { get; set; }
  71. public MethodInfo Method { get; set; }
  72. public string PermissionState { get; set; }
  73. public Type PermissionType { get; set; }
  74. public object PermitOnlySetInstance { get; set; }
  75. public string RefusedSet { get; set; }
  76. public string Url { get; set; }
  77. }
  78. }