Developing Dynamics 365 Business Central Extensions: use code analysis to prevent strange errors.

You’ve developed a marvellous 😀 extension for Dynamics 365 Business Central and tested it on your development sandbox without problems. Now, you try to deploy it to a production environment via the Upload Extension action on the Extension Management page and voilà:

Publish operation failed. Details: Extension validation failed. View the error details for more information.

What error details? Unfortunately, Microsoft actually does not provide a great way to see what is the cause of these types of errors, but they are actively working on improving the error status information in Dynamics 365 Business Central, so stay tuned.

But, what can I do now? I’ve experienced many times that this error is caused by rules not met on your extension. I think it’s extremely helpful to activate the code analysis tools that Microsoft actually provides for the AL language because they can help you to prevent failures.

The AL Language extension for Visual Studio Code contains three code analyzers:

  • CodeCop is an analyzer that enforces the official AL Coding Guidelines. For more information, see CodeCop Analyzer Rules.
  • PerTenantExtensionCop is an analyzer that enforces rules that must be respected by extensions meant to be installed for individual tenants. For more information, see PerTenantExtensionCop Analyzer Rules.
  • AppSourceCop is an analyzer that enforces rules that must be respected by extensions meant to be published to Microsoft AppSource. For more information, see AppSourceCop Analyzer Rules.

There’s a great blog post by Waldo that explains how to activate, use and customize them, so I don’t want to write more on that here (he’s the king!).

On your Visual Studio code, you can go on File -> Preferences -> Settings and here activate the analyzers by adding the following line in the User or Workspace settings:


This line activates ALL the AL code analyzers and in my opinion it’s only for real world purists 😀

This is what happens when I compile an extension that works and that doesn’t have any types of errors or warnings when I don’t have the analyzers activated:


As you can see, there are lots of “unuseful” warning regarding parenthesis, BEGIN..END and so on.

Activating all the analyzers could be too much, but I suggest to activate at least the PerTenantExtensionCop analyzers when you want to deploy your extension to a production environment (per-tenant extension, not AppSource):


Now, if you compile the previous extension with all this analyzers activated, this is the result:


Now the compiler listed only problems that can cause conflicts when installing the extension on a production tenant.

My suggestion (only based on experience, so feel free to comment) is to solve all these problems in your code and then deploy to production. The previously reported error in many cases will disappear. If not, your last chance is to call Microsoft 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.