PermissionSet.Assert Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Declares that the calling code can access the resource protected by a permission demand through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. Using Assert() can create security vulnerabilities.

C#
public void Assert();
C#
public virtual void Assert();

Implements

Exceptions

The PermissionSet instance asserted has not been granted to the asserting code.

-or-

There is already an active Assert() for the current frame.

Remarks

This is the only way to assert multiple permissions at the same time within a frame because only one Assert can be active on a frame. Assert is only effective for granted permissions. Call the CodeAccessPermission.RevertAssert or CodeAccessPermission.RevertAll method to cancel an active Assert.

Caution

Because calling the Assert method removes the requirement that all code in the call chain must be granted permission to access the specified resource, it can open up security vulnerabilities if used incorrectly or inappropriately. Therefore, it should be used with great caution.

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also