Business Central 2023 wave 1 (BC22): New rule to enforce pragma warning ‘disable’ specifying a disabled rule (CodeCop Warning AA0246)

Dynamics 365 Business Central

Hi, Readers.
Dynamics 365 Business Central 2023 wave 1 (BC22) is generally available last week. More details: Dynamics 365 Business Central 2023 release wave 1 (BC22)

I will continue to test and share some new features that I hope will be helpful.

New rule to enforce pragma warning ‘disable’ specifying a disabled rule:

Business value:
It is possible to use the #pragma warning disable to disable all rules. This is often not the intended use, so to support gating this, a new CodeCop rule has been introduced that allows mandating that disabled rules are specified explicitly.

What is Pragma Warning? We briefly discussed it in Preprocessor Directives in AL (Conditional Directives, Regions, Pragmas) before, let’s recap.

Pragma Warning:

The #pragma warning instruction can enable or disable certain warnings. This can be used as a solution to avoid getting warnings on, for example, string length on fields that you cannot change. With the #pragma warning disable statement you disable the emit of the warning for a specific location in code, and with #pragma warning restore you restore the warning back to it’s original state. If you do not restore, the disable instruction is valid for the rest of the file.

For example, there are 100 warnings in the following object “”.

You can enter “#pragma warning disable AL0604” to ignore “AL0604” warning.

Or, enter “#pragma warning disable” to ignore all warning. (In previous versions, there was no warning)

With this wave, a new, optional CodeCop rule AA0246 has been added. Enabling this allows you to enforce that, when suppressing diagnostics using the #pragma warning disable, the code(s) of the diagnostics to suppress must be specified instead of suppressing all analyzer diagnostics and compiler warnings.

For example,

CodeCop Warning AA0246:

Suppressing all diagnostics is not allowed. Specify the diagnostic(s) that you want to suppress. AL (AA0246)

Give it a try!!!😁


Hope this will help.

Thanks for reading.



Copied title and URL