Sunday, August 19, 2018

D365 Business Central - Use code analysis to prevent strange errors

Hello Friends,

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 fail to publish. 
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. - After June 2018, Microsoft provide the detail descriptive error logs. 
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:
ALCodeAnalysis_01.jpg
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:
ALCodeAnalysis_02.jpg
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):
ALCodeAnalysis_03.jpg
Now, if you compile the previous extension with all this analyzers activated, this is the result:
ALCodeAnalysis_04.jpg
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 ðŸ™‚

5 comments:

  1. Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up. 
    Oracle training in btm
    Oracle Online Training
    Oracle training in chennai
    Oracle training in Bangalore

    ReplyDelete