Edit

Control AL compiler warnings with pragma directives

APPLIES TO: Business Central 2020 release wave 2 and later

The #pragma warning disable directive suppresses specified compiler warnings from its location until a matching #pragma warning restore directive or the end of the file. If you omit the warning list, the directive applies to all configurable warnings.

Important

Suppress warnings only when you can't address their cause. A warning can become an error in a later release and break your extension.

Syntax

#pragma warning disable warning-list  
#pragma warning restore warning-list  

Parameters

warning-list

A comma-separated list of warning IDs or numeric warning codes, such as AL0468, AL0604.

When you don't specify warning IDs, disable suppresses all configurable warnings from that point forward. restore clears the pragma warning state and returns all warnings to their default or project-configured reporting state.

Note

To find warning IDs, build your AL project in Visual Studio Code and check the Output window. Learn more about code analysis in Using the code analysis tool.

Example

The following example illustrates how the specific rule AL0468 is temporarily turned off for a specific field definition.

table 50110 MyTable
{
    fields
    {
        #pragma warning disable AL0468
        field(1; TableWithLongIdentifierThatExceedsOurMax; Integer) { }
        #pragma warning restore AL0468
    }
}

Development in AL
AL development environment
Pragma directive in AL
Conditional directives
Deprecating explicit and implicit with statements