Host protection attributes and CLR integration programming

Applies to: SQL Server

The common language runtime (CLR) provides a mechanism to annotate managed application programming interfaces (APIs) that are part of the .NET Framework. These attributes might be of interest to a host of the CLR, such as SQL Server. Examples of such host protection attributes (HPAs) include:

  • SharedState, which indicates whether the API exposes the ability to create or manage shared state (for example, static class fields).

  • Synchronization, which indicates whether the API exposes the ability to perform synchronization between threads.

  • ExternalProcessMgmt, which indicates whether the API exposes a way to control the host process.

Given these attributes, SQL Server specifies a list of HPAs that are disallowed in the hosted environment through code access security (CAS). The CAS requirements are specified by one of three SQL Server permission sets: SAFE, EXTERNAL_ACCESS, or UNSAFE. One of these three security levels is specified when the assembly is registered on the server, using the CREATE ASSEMBLY statement. Code executing within the SAFE or EXTERNAL_ACCESS permission sets must avoid certain types or members that have the System.Security.Permissions.HostProtectionAttribute attribute applied. For more information, see Create an assembly and CLR integration programming model restrictions.

The HostProtectionAttribute isn't a security permission as much as a way to improve reliability, in that it identifies specific code constructs, either types or methods, that the host might disallow. The use of the HostProtectionAttribute enforces a programming model that helps protect the stability of the host.

Host protection attributes

HPAs identify types or members that don't fit the host programming model and represent the following increasing levels of reliability threat:

  • Are otherwise benign.
  • Could lead to destabilization of server-managed user code.
  • Could lead to destabilization of the server process itself.

SQL Server disallows the use of a type or member that has a HostProtectionAttribute that specifies a System.Security.Permissions.HostProtectionResource enumeration with a value of ExternalProcessMgmt, ExternalThreading, MayLeakOnAbort, SecurityInfrastructure, SelfAffectingProcessMgmnt, SelfAffectingThreading, SharedState, Synchronization, or UI. This prevents the assemblies from calling members that enable sharing state, perform synchronization, might cause a resource leak on termination, or affect the integrity of the SQL Server process.

Disallowed types and members

The following articles identify types and members whose HostProtectionResource values SQL Server disallows.

The lists in these articles were generated from the supported assemblies. For more information, see Supported .NET Framework libraries.

In this section

Article Description
Disallowed types and members in Microsoft.VisualBasic.dll Lists the types and members in Microsoft.VisualBasic.dll whose HPA values are disallowed.
Disallowed types and members in mscorlib.dll Lists the types and members in mscorlib.dll whose HPA values are disallowed.
Disallowed types and members in System.dll Lists the types and members in System.dll whose HPA values are disallowed.
Disallowed types and members in System.Data.dll Lists the types and members in System.Data.dll whose HPA values are disallowed.
Disallowed types and members in System.Core.dll Lists the types and members in System.Core.dll whose HPA values are disallowed.