Partager via


CodeAccessPermission.assert Method

Definition

Declares that the calling code can invoke an API that is protected by a permission.

public:
 void assert();
public void assert ();
member this.assert : unit -> unit
Public Sub assert ()

Remarks

You must call the assert method in the derived class for a protected API before you invoke the API. For more information about APIs that are protected by permissions, see Secured APIs. You must call the assert method on the same tier, usually the server tier, that the corresponding CodeAccessPermission::demand method is called on before the protected API is executed. Call a method on the server tier from one of the following:

  • A server static method
  • A class instance method that is set to run on the server by using the RunOn class property

Finance and Operations does not support multiple, successive calls to the assert method in the same calling code. Either call the CodeAccessPermission::revertAssert method between each call to the assert method, or call the CodeAccessPermission::assertMultiple method. If you make multiple, successive calls to the assertmethod, the Infolog displays an error when you execute the code.

The following code example shows a call to the assert method before the AsciiIo Class class that is protected by a permission is invoked. The assert method is a member of the FileIOPermission class that is derived from the CodeAccessPermission class.

server static void main(Args args) 
{ 
    FileIoPermission _perm; 
    AsciiIo a; 
    _perm = new FileIoPermission("c:\File.txt",'r'); 
    _perm.assert(); 
    // Invoke the protected API. 
    a = new AsciiIo("c:\File.txt",'r'); 
}

Applies to