Dynamics 365 Business Central: please always check AL warnings!

This is a quick post that want to describe a curious thing discovered 3 days ago. A partner contacted me on a social network (yes, I answer also on my socials but please don’t abuse on questions here, I have an email address…) and said me that he had problems on deploying an update of a per-tenant extension (big extension) to a SaaS tenant (the extension was previously working).

The error that occours when publishing the extension was the following:

Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Symbols.ExtendedErrorTypeSymbol' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Symbols.FieldSymbol'.

Nothing more…

My first question to the partner was: do you have errors on your code? Answer: NO. And do you have warnings? CodeAnalysis reminds me to something related to code compiling… Answer: YES, a lot of warnings, but we don’t care about them now.

Oh wait… you cannot forgot warnings without a check. So, we started checking the big list of warnings and I’ve discovered the following situation: in this extension (different developers works on the code), the partner creates a tableextension object for the Vendor table for adding a big set of fields.

Then, in the new extension’s update, they modify the property of one of these fields in the following way (they forgot that the field was added in the tableextension object itself):

As you can see, the field here is modified before its declaration. The AL language signals you that this is a warning:

But unfortunately this is signaled only as a warning, not as an error. If you forgot to fix this warning and you deploy this extension to your SaaS tenant, you receive the above error message (that it’s not so intuitive for the developers I think). In my opinion, this warning should be converted as an error immediately.

Please always check warnings in your code! A clean code should not have any warnings. The only admitted warnings where you can delay the fixes are the warnings related to Microsoft’s obsoletes things, where you have a time window to adapt your code to the new Microsoft’s refactored things. But at the end your extensions should always be “warning free”.

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

You are commenting using your Twitter 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.