CodeAccessPermission.assert Method

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

Syntax

public void assert()

Run On

Called

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

Microsoft Dynamics AX 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.

Examples

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'); 
}

See Also

CodeAccessPermission Class

CodeAccessPermission Class