Error “cannot be used” for “Extension” development
During compilation, this error message may appear “cannot be used” for “Extension” development” if you attempt to compile using incorrect Business Central v15 server settings.
The problem occurs when [Scope (‘OnPrem’)] is inserted in the code and the server is not enabled to manage it.
To resolve, remove the [Scope (‘OnPrem’)] statement or change the server options by setting to “Onpremise”. In fact the target levels have changed, from version 15 and platform 4.0 it is necessary to switch to “OnPrem” or “Cloud” instead of the old options now deprecated.
Allowed Extension Target Level
Note: The Internal, Extension, Solution, and Personalization options have been deprecated and replaced with Cloud and OnPrem
About “OnPrem” option
If you specify the “OnPrem” option, the allowed compilation target is set to everything on-premises. The OnPrem setting allows using all restricted APIs. The target setting in the app.json file must also be set to OnPrem.
Configuring extension target for an extension
In the manifest of an extension (the app.json file), you can set the target property to specify the compilation target of an extension. The available values are Internal, Extension, OnPrem, and Cloud.
“The Internal and Extension values have been deprecated starting with runtime 4.0 and replaced by the OnPrem and Cloud respectively”
The target property informs the compiler which APIs can be used within the current project.
- If you specify “target”:”OnPrem” you can use any platform APIs and .NET types. This is the most permissive target. It is only if you specify this target that you can use methods marked with Scope(‘OnPrem’) or tables with the property Scope (Tables) set to OnPrem.
- If you specify “target”:”Cloud” you can only use APIs that are safe for use in a cloud environment. If the target is set to Cloud, the extension cannot use any method marked with Scope(‘OnPrem’) or table with the property Scope set to OnPrem, even if those elements are declared within the same extension. For example, if you have two extensions; A and B. Extension A has an app.json target setting “target”: “OnPrem” and defines a method with the Scope Attribute set to [Scope(‘OnPrem’)].
By default this is Cloud. The setting currently has the following options: Internal, Extension, OnPrem, and Cloud. The Internal and Extension settings are being deprecated. For on-premises, you can set this to OnPrem to get access to otherwise restricted APIs and .NET Interop. The Business Central Server setting must then also be set to OnPrem.
The version of the runtime that the project is targeting. The project can be published to the server with an earlier or the same runtime version. The available options are: 1.0 – Business Central April 2018 release, 2.2 – Business Central October 2018 release CU 2, 3.0 – Business Central April 2019 release, and 4.0 – Business Central 2019 release wave 2.
Methods and tables scope
Methods can be marked with the [Scope()] attribute to specify the compilation target and tables can be marked with the Scope property. Both instruct the compiler which target the method or table can be used in.
Message(‘My procedure is available externally.’);
Message(‘My procedure is available internally.’);
To enable AL Code Analysis
- Configure extension settings (AL Language)