Error “cannot be used” for “Extension” development

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’)].


App.json file



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.



procedure MyProcedureForCloud()


Message(‘My procedure is available externally.’);



procedure MyProcedureForOnPrem()


Message(‘My procedure is available internally.’);



To enable AL Code Analysis

  • Configure extension settings (AL Language)

Edit settings.json

“al.enableCodeAnalysis”:= true;

One thought on “Error “cannot be used” for “Extension” development

  • 15 April 2020 at 3:52 PM

    Thanks for clarifying the ‘scope’ parameters. However, what’s still not clear to me is how this is reflected in the ‘one code-base’ principle that MS advocates. Is there just one BC app or different apps (one for Saas vs another for OnPrem) Downloading the code from the container (which seems to me the ‘Saas’ solution), shows an app.json file with “target”: “OnPrem”. Also lots of .al files still contain the [Scope(‘OnPrem’)] attribute. How can I see the real difference (if there’s any) in the Base Application objects used in Saas vs OnPrem?

    The reason why I’m asking is that we want to prepare our OnPrem solution for Cloud, still using one single code-base. Since there’s a lot of functions containing dotnet / non-Saas supported features, I was thinking of tagging these functions with [Scope(‘OnPrem’)], but setting the target to ‘Cloud’, so the app would build for Saas, without access to the OnPrem functions. However, this seems not to work.

    Am I obliged to create 2 code-bases? One with OnPrem functions + target OnPrem and another without OnPrem functions + target Cloud? (Another option is to move away OnPrem functions to a dependend extension instead.)

Comments are closed.