{"title":"AppSourceCop Error AS0022","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/appsourcecop-as0022/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0022, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0022","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"An external scope cannot be removed.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"AppSourceCop Error AS0022","slug":"appsourcecop-error-as0022","at":0,"chars":3766},{"level":2,"title":"Description","slug":"description","at":64,"chars":52},{"level":2,"title":"Remarks","slug":"remarks","at":116,"chars":392},{"level":2,"title":"Code examples triggering the rule","slug":"code-examples-triggering-the-rule","at":508,"chars":1815},{"level":3,"title":"Example 1 - Adding a local access modifier","slug":"example-1---adding-a-local-access-modifier","at":812,"chars":716},{"level":3,"title":"Example 2 - Changing the Scope attribute from 'Cloud' to 'OnPrem'","slug":"example-2---changing-the-scope-attribute-from-cloud-to-onprem","at":1528,"chars":795},{"level":2,"title":"Code examples not triggering the rule","slug":"code-examples-not-triggering-the-rule","at":2323,"chars":1296},{"level":3,"title":"Example 1 - Removing a local access modifier","slug":"example-1---removing-a-local-access-modifier","at":2679,"chars":355},{"level":3,"title":"Example 2 - Changing the Scope attribute from 'OnPrem' to 'Cloud'","slug":"example-2---changing-the-scope-attribute-from-onprem-to-cloud","at":3034,"chars":585},{"level":2,"title":"Related information","slug":"related-information","at":3619,"chars":147}],"text":"# AppSourceCop Error AS0022\nAn external scope cannot be removed\n## Description\nAn external scope cannot be removed.\n## Remarks\nThis rule verifies that procedures which were exposed to dependent extensions in the previous version of the extension, remain exposed to other extensions.\nThe availability of a procedure is defined by:\n the access modifier set on the object declaring the procedure\n the access modifier set on the procedure\n the ../attributes/devenv-scope-attribute that is added on the procedure\n## Code examples triggering the rule\nIn the following examples, version 1.0 of the extension defines a procedure which is public and available for Cloud development.\nVersion 1.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [Scope('Cloud')]\n    procedure MyProcedure()\n    begin\n    end;\n}\n```\n### Example 1 - Adding a local access modifier\nVersion 2.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [Scope('Cloud')]\n    local procedure MyProcedure()\n    begin\n    end;\n}\n```\nIn version 2.0, the procedure is only accessible within its declaring codeunit. If a dependent extension called this procedure, this will lead to a compilation error similar to `'MyProcedure()' is inaccessible due to its protection level. (AL0161)`.\nFor example, the following extension compiles when depending on version 1.0, but fails to compile with version 2.0:\n```al\ncodeunit 50120 AnotherCodeunit\n{\n    procedure AnotherMethod()\n    var\n        c: Codeunit MyCodeunit;\n    begin\n        c.MyProcedure();\n    end;\n}\n```\n### Example 2 - Changing the Scope attribute from 'Cloud' to 'OnPrem'\nVersion 2.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [Scope('OnPrem')]\n    procedure MyProcedure()\n    begin\n    end;\n}\n```\nIn version 2.0, the procedure is only available for OnPrem development. If a dependent extension uses the Cloud compilation target in the app.json and calls this procedure, this will lead to a compilation error similar to `The type or method 'MyProcedure' cannot be used for 'Extension' development. (AL0296)`.\nFor example, the following extension compiles when depending on version 1.0, but fails to compile with version 2.0:\n```al\ncodeunit 50120 AnotherCodeunit\n{\n    procedure AnotherMethod()\n    var\n        c: Codeunit MyCodeunit;\n    begin\n        c.MyProcedure();\n    end;\n}\n```\n## Code examples not triggering the rule\nIn the following examples, version 1.0 of the extension defines a procedure which does not have a return type.\nVersion 1.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [Scope('OnPrem')]\n    procedure MyOnPremProcedure()\n    begin\n    end;\n\n    local procedure MyLocalProcedure()\n    begin\n    end;\n}\n```\n### Example 1 - Removing a local access modifier\nVersion 2.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [Scope('OnPrem')]\n    procedure MyOnPremProcedure()\n    begin\n    end;\n\n    procedure MyLocalProcedure()\n    begin\n    end;\n}\n```\nIn version 2.0, the procedure MyLocalProcedure is now public and becomes available to dependent extensions.\n### Example 2 - Changing the Scope attribute from 'OnPrem' to 'Cloud'\nVersion 2.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [Scope('Cloud')]\n    procedure MyOnPremProcedure()\n    begin\n    end;\n\n    local procedure MyLocalProcedure()\n    begin\n    end;\n}\n```\nIn version 2.0, the procedure MyOnPremProcedure becomes available for both OnPrem and Cloud development. Any dependent extension can now call this procedure, regardless of the compilation target specified in their app.json. The default Scope of a procedure is Cloud. Removing the attribute is then also allowed.\n## Related information\nAppSourceCop Analyzer<appsourcecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}