{"title":"AppSourceCop Error AS0021","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/appsourcecop-as0021/","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-as0021, 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-as0021","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 argument in an event attribute cannot be changed to false.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"AppSourceCop Error AS0021","slug":"appsourcecop-error-as0021","at":0,"chars":3834},{"level":2,"title":"Description","slug":"description","at":90,"chars":175},{"level":2,"title":"Remarks","slug":"remarks","at":265,"chars":401},{"level":2,"title":"Code examples triggering the rule","slug":"code-examples-triggering-the-rule","at":666,"chars":2161},{"level":3,"title":"Example 1 - A business type event stops exposing its sender","slug":"example-1---a-business-type-event-stops-exposing-its-sender","at":703,"chars":988},{"level":3,"title":"Example 2 - An integration type event stops exposing global variables","slug":"example-2---an-integration-type-event-stops-exposing-global-variables","at":1691,"chars":1136},{"level":2,"title":"Code examples not triggering the rule","slug":"code-examples-not-triggering-the-rule","at":2827,"chars":860},{"level":3,"title":"Example 1 - An event does not change over time","slug":"example-1---an-event-does-not-change-over-time","at":2868,"chars":389},{"level":3,"title":"Example 2 - An event starts exposing its sender","slug":"example-2---an-event-starts-exposing-its-sender","at":3257,"chars":430},{"level":2,"title":"Related information","slug":"related-information","at":3687,"chars":147}],"text":"# AppSourceCop Error AS0021\nAn argument in an event attribute cannot be changed to false.\n## Description\nAn argument in an event attribute cannot be changed to false. This is not allowed because it may break dependent extensions that have subscribed to this event.\n## Remarks\nThis rule verifies that events that are available from other extensions such as ../attributes/devenv-businessevent-attribute type events or ../attributes/devenv-integrationevent-attribute type events do not stop exposing their sender or their global variables.\nThis does not apply to ../attributes/devenv-internalevent-attribute type events as they are not exposed to dependent extensions.\n## Code examples triggering the rule\n### Example 1 - A business type event stops exposing its sender\nVersion 1.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [BusinessEvent(true)]\n    procedure MyEvent()\n    begin\n    end;\n}\n```\nVersion 2.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [BusinessEvent(false)]\n    procedure MyEvent()\n    begin\n    end;\n}\n```\nIn the newer version, the sender exposed by MyEvent is not accessible to subscribers anymore. If a dependent extension relies on it, this will lead to a compilation error similar to `The member referenced by event subscriber 'MyProcedure' parameter 'sender' is not found (AL0282)`.\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    [EventSubscriber(ObjectType::Codeunit, Codeunit::MyCodeunit, 'MyEvent', '', true, true)]\n    local procedure MyProcedure(sender: Codeunit MyCodeunit)\n    begin\n        // Subscriber logic\n    end;\n}\n\n```\n### Example 2 - An integration type event stops exposing global variables\nVersion 1.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [IntegrationEvent(true, true)]\n    procedure MyEvent()\n    begin\n    end;\n\n    var\n        myGlobalVariable: Integer;\n}\n```\nVersion 2.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [IntegrationEvent(true, false)]\n    procedure MyEvent()\n    begin\n    end;\n\n    var\n        myGlobalVariable: Integer;\n}\n```\nIn the newer version, the global variables exposed by MyEvent are not accessible to subscribers anymore. If a dependent extension relies on global variables, this will lead to a compilation error similar to `The member referenced by event subscriber 'MyProcedure' parameter 'myGlobalVariable' is not found (AL0282)`.\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    [EventSubscriber(ObjectType::Codeunit, Codeunit::MyCodeunit, 'MyEvent', '', true, true)]\n    local procedure MyProcedure(myGlobalVariable: Integer)\n    begin\n        // Subscriber logic\n    end;\n}\n```\n## Code examples not triggering the rule\n### Example 1 - An event does not change over time\nVersion 1.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [BusinessEvent(false)]\n    procedure MyEvent()\n    begin\n    end;\n}\n```\nVersion 2.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [BusinessEvent(false)]\n    procedure MyEvent()\n    begin\n    end;\n}\n```\nThe event remains the same from one version to the other.\n### Example 2 - An event starts exposing its sender\nVersion 1.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [BusinessEvent(false)]\n    procedure MyEvent()\n    begin\n    end;\n}\n```\nVersion 2.0 of the extension:\n```al\ncodeunit 50100 MyCodeunit\n{\n    [BusinessEvent(true)]\n    procedure MyEvent()\n    begin\n    end;\n}\n```\nIn the newer version of the extension, the sender becomes exposed through the business type event.\n## Related information\nAppSourceCop Analyzer<appsourcecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}