<PackageReference Include="System.Security.Permissions" Version="10.0.0-preview.6.25358.103" />

HostProtectionException

The exception that is thrown when a denied host resource is detected.
using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Security.Permissions; using System.Text; namespace System.Security { [Serializable] [Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId = "SYSLIB0003", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] [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; } [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}")] [EditorBrowsable(EditorBrowsableState.Never)] 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(); } [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}")] [EditorBrowsable(EditorBrowsableState.Never)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("ProtectedResources", ProtectedResources, typeof(HostProtectionResource)); info.AddValue("DemandedResources", DemandedResources, typeof(HostProtectionResource)); } } }