<PackageReference Include="System.Security.Permissions" Version="9.0.5" />

HostProtectionException

The exception that is thrown when a denied host resource is detected.
using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Security.Permissions; using System.Text; namespace System.Security { [Serializable] [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class HostProtectionException : SystemException { private const string ProtectedResourcesName = "ProtectedResources"; private const string DemandedResourcesName = "DemandedResources"; private const int E_HostProtection = -2146232768; public HostProtectionResource DemandedResources { get; } public HostProtectionResource ProtectedResources { get; } public HostProtectionException() { base.HResult = -2146232768; ProtectedResources = HostProtectionResource.None; DemandedResources = HostProtectionResource.None; } public HostProtectionException(string message) : base(message) { base.HResult = -2146232768; ProtectedResources = HostProtectionResource.None; DemandedResources = HostProtectionResource.None; } public HostProtectionException(string message, Exception e) : base(message, e) { base.HResult = -2146232768; ProtectedResources = HostProtectionResource.None; DemandedResources = HostProtectionResource.None; } public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources) : base(message) { base.HResult = -2146232768; ProtectedResources = protectedResources; DemandedResources = demandedResources; } protected HostProtectionException(SerializationInfo info, StreamingContext context) : base(info, context) { ProtectedResources = (HostProtectionResource)info.GetValue("ProtectedResources", typeof(HostProtectionResource)); DemandedResources = (HostProtectionResource)info.GetValue("DemandedResources", typeof(HostProtectionResource)); } private static void AppendResourceString(string resourceString, object attr, StringBuilder sb) { if (attr != null) { sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append(resourceString); sb.Append(Environment.NewLine); sb.Append(attr); } } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(base.ToString()); AppendResourceString(System.SR.HostProtection_ProtectedResources, ProtectedResources, stringBuilder); AppendResourceString(System.SR.HostProtection_DemandedResources, DemandedResources, stringBuilder); return stringBuilder.ToString(); } public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("ProtectedResources", ProtectedResources, typeof(HostProtectionResource)); info.AddValue("DemandedResources", DemandedResources, typeof(HostProtectionResource)); } } }