Publish-NAVApp : Extension compilation failed

Dynanmics 365 Business Central logo

Have you ever tried to publish an app-file using the Publish-NavApp PowerShell Cmdlets on a on-premises Microsoft Dynamics 365 Business Central and was stopped by errors like these:

Publish-NAVApp : Extension compilation failed
source/codeunits/Cod13653.PaymentExportManagement.al(4,27): error AL0185: Codeunit 'Payment Export Mgt' is missing
source/codeunits/Cod13656.DataMigration.al(15,28): error AL0185: Codeunit '9002' is missing
source/codeunits/Cod13650.FIKManagement.al(54,24): error AL0185: Table 'Payment Method' is missing
source/codeunits/Cod13650.FIKManagement.al(98,29): error AL0185: Table 'Company Information' is missing
source/codeunits/Cod13650.FIKManagement.al(126,59): error AL0185: Table 'Bank Acc. Reconciliation' is missing
source/codeunits/Cod13650.FIKManagement.al(128,18): error AL0185: Table 'Bank Account' is missing
source/codeunits/Cod13650.FIKManagement.al(129,22): error AL0185: Table 'Data Exch. Def' is missing
source/codeunits/Cod13650.FIKManagement.al(130,26): error AL0185: Table 'Data Exch. Mapping' is missing
[…]
source/codeunits/Cod13657.FIKSubscribers.al(360,46): error AL0132: 'Page' does not contain a definition for 'Payment Application'
 source/codeunits/Cod13657.FIKSubscribers.al(361,56): error AL0185: Page 'Payment Application' is missing
 source/codeunits/Cod13657.FIKSubscribers.al(361,111): error AL0185: Table 'Bank Acc. Reconciliation Line' is missing
 At line:10 char:1
 Publish-NAVApp -ServerInstance $ServerInstance -SkipVerification -Pat …
 ~~~~~~~~~~~~~~~~~ CategoryInfo          : InvalidOperation: (:) [Publish-NAVApp], InvalidOperationException
 FullyQualifiedErrorId : MicrosoftDynamicsNavServer$DynamicsNAV/nav-systemapplication,Microsoft.Dynamics.Nav.Apps.Management.Cmdlets.PublishNavApp 

Note – it seems that all objects are missing!?

It seems illogical, but it is fixed by running symbol generation:

  1. In the Microsoft Dynamics 365 Business Central administrative console you should set the parameter Enable loading application symbol references at server startup in the Development group.
  2. Then you should go to the Program Files (x86) installation folder for the Role Tailored Client (typically C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\<version>\RoleTailored Client) and run this command:
finsql.exe Command=generatesymbolreference, Database="<application sql database>", ServerName=<sql server host name>, ntauthentication=no, username=<sql server username>, password=<sql server password>

Note: The finsql.exe command will start a background finsql.exe process (you can see it in Windows Task Manaer). When it finishes it will write one or two text-files in the Role Tailored Client directory – one with status (filename navcommandresult.txt) and the other one if any errors happens (filename naverrorlog.txt).

These two steps fixed it for me.

You can read more about the symbol generation in the Microsoft documentation by clicking here!

Bad Request – Error in query syntax.

PowerShell logo

No, this is not an error in WordPress on this server – “Bad Request – Error in query syntax.” is in fact the intended subject for this Blog post :-).

If you are running OData WebServices towards you Microsoft Dynamics NAV or 365 Business Central (DBC) and you get this error – and you have a forward slash ( “/” ) in the company name in question, then this Blog post is for you :-).

You have just discovered that Excel, PowerShell.exe and/or older version of PowerShell ISE cannot work with OData URLs with a forward slash in the …/Company(‘<my company name>’)/… part of the URL.

A obvious solution is to rename the company in NAV/DBC – but that is not really a neat solution, is it?

According to this Microsoft blog post, another far superior solution exists. NAV/DBC supports two syntaxes when stating the company name.

The “classic” one you use for OData version 3 when you got the error:

https://<my hostname>:<my odata port>/<my instance>/OData/Company('<my company')/<my webservice>

…or the corresponding OData version 4 one:

https://<my hostname>:<my odata port>/<my instance>/ODataV4/Company('<my company')/<my webservice>

…and another one for working around this error:

https://<my hostname>:<my odata port>/<my instance>/OData/<my webservice>?company='<my company>'

…or the corresponding OData version 4 one:

https://<my hostname>:<my odata port>/<my instance>/ODataV4/<my webservice>?company='<my company>'

Note that you can off cause add additonal parameters (selecting tenant or setting filters etc.) to the URL using the ampersand sign ( “&” ) – just like you do when construction any URL.

Congratulations – you solved your problem πŸ™‚

If you want to learn more about OData towards NAV/DBC, I suggest you visit these links:

“External Azure Active Directory” users and Single-Sign-On in Dynamics 365 Business Central

Dynanmics 365 Business Central logo

If you are setting up Single-Sign-On (SSO) for Dynamics 365 Business Central (DBC) and you are only able to authenticate users local to the Azure Active Directory (i.e. non Guest or “External Azure Active Directory” users), then you might have stumbled across the same error as me.

The error manifests itself by allowing you to log in using SSO, but just when the DBC webclient is suppose to open, you get this error:

Your user name or password is incorrect, or you do not have a valid account in Dynamics 365 Business Central.

The problems is that a user with that authentication e-mails IS in fact present in DBC – so the error makes no sense.

Also you will sometimes get a warning in the Event Viewer that the SSO token was valid, but the user could not be found in DBC.

As mentioned the local domains works fine, it is only if you try to add external users and authenticate with those it does not work:

User type: Guest
Source: External Azure Active Directory

I’ve seen this error in Microsoft Dynamics 365 Business Central 2018 fall release with cumulative update 1 and 2.

I’m aware that you – with powershell – can change a User type Guest to a User type Member. I tried it, but the result was the exact same. So “no cigar” for that solution.

After upgrading the platform to the latest Cumulative Update (which is 7 while I’m writing this), the error is completely gone. So there you have your fix :-).

Note: I’ve not tested all the CUs between 2 and 7 to figure out when it was fixed or if there is a entry in the fix list that mentions this – so if you have more knowledge about that, please share by adding a comment.

Broken Microsoft Dynamics 365 Business Central Single-Sign-On with Multi-Tenancy setup

Dynanmics 365 Business Central logo

After having a Single-Sign-On (towards Azure Active Directory)/Multi-Tenancy setup running on Dynamics NAV 2018 for some time, I tried to create the same setup with Microsoft Dynamics 365 Business Central 2018 fall release.

And to my surprise it failed with this error just after logging in: “The value for the WSFederationLoginEndpoint configuration settings cannot be empty.”. My “WSFederationLoginEndpoint” setting was NOT empty, so the error does not make any sense.

The value for the WSFederationLoginEndpoint configuration settings cannot be empty.
The value for the WSFederationLoginEndpoint configuration settings cannot be empty.

It puzzled me for a while because these setups was working without any problems:

  • Dynamics NAV 2018, Single Tenant
  • Dynamics NAV 2018, Multi Tenant
  • Dynamics 365 Business Central 2018 fall release, Single Tenant

So the Single Tenant BC was working, but failed as soon as I configured it for Multi Tenancy.

Finally after weeks of messing around I gave up and reached out to my contacts from Microsoft Development Center Copenhagen to see if they could help me solve the issue (first I off cause raised a ticket with Microsoft Support). Luckily Freddy from https://freddysblog.com/ knew exactly what was wrong with my setup – and was able to send me the exact solution. And made the effort to do this on a Saturday morning! πŸ™‚

THANK YOU FREDDY πŸ™‚ !!! – please click here to visit his blog!

Oh – I almost forgot. If you have this error, empty these configurations settings from the Service Tier:

  • AzureActiveDirectoryClientId
  • AzureActiveDirectoryClientSecret

These two settings are used in Dynamics NAV 2018, but should be left empty in Microsoft Dynamics 365 Business Central.

Broken AL in Visual Studio Code October 2018 release (1.29)

Visual Studio Code logo

October 2018 release (1.29) for Visual Studio Code was just released, but unfortunately it breaks the possibility to publish AL extensions to your Dynamcs NAV / 365 Business Central.

Don’t blame the guys behind Visual Studio Code, this one is probably on the AL extension guys.

Only solution i know is to downgrade Visual Studio Code to the September 2018 (1.28.2) release or earlier for now, but I’m sure it will be fixed in the next CUs for NAV/BC.

The symptoms of this error is:

  • When publishing you don’t get any output in the VSC DEBUG CONSOLE. Only the OUTPUT shows the “normal” behaviour.
  • The Web Client won’t start after the publish.
  • The extension is not published if you start Web or Windows Client manually and check.
  • Your Windows Event Viewer will have several errors from your NAV Service tier with lots of call stack for each attempt to publish. The important text to search for is errors like:
    • Message (InvalidOperationException): RootException: InvalidOperationException
      This operation cannot be performed after the response has been submitted.
    • Message Failed request — Method:GET; Url:http://localhost:7349/NAV130_GSL/dev/metadata; StatusCode:InternalServerError; ReasonPhrase:Internal Server Error; Token:
    • Message (InvalidOperationException): RootException: InvalidOperationException
      Dynamic operations can only be performed in homogenous AppDomain.

The missing AL language support for VSC October 2018 release (1.29) was mentioned very briefly at NavTechDays 2018 in one of the first sessions (forgot which one), but I’ve not been able to find it on Google, so that is why i provide this blog post.

These kind of errors is almost impossible to trouble shoot if you cannot Google them :-).

Hint: Visual Studio Code will auto-update to the newest release automatically. To disable this, go to File/Preferences/Settings and change the “update.channel” to “none”. I highly recommend that you return this setting to its original value when the AL-language guys fix this error.

Cent and Yen in Dynamics NAV 2018

Microsoft Dynamics NAV logo

If you run a Danish Dynamics NAV and get objects from outside Denmark, you might experience the Danish letter ΓΈ/Ø beeing replaced by Β’/Β₯ (the sign for Cent and Yen).

The fix?
Simply export all your objects as text, run them through the following powershell and import them again.

(((Get-Content -encoding Oem "InFile.txt") -replace ([char]8250),([char]251)) -replace ([char]157),([char]238)) | Set-Content -encoding Oem "OutFile.txt"

 

Finish off by a compile and syncronize all tables.

This is off cause on your own risk, so start by taking a full backup of your NAV system/server.


2018-12-20 Updated: powershell improved and now using unicode values of chars

My Dynamics NAV App is FUBAR (updated 2018-06-22 with new solution)

Microsoft Dynamics NAV logo

For readers not knowing what FUBAR is, please see Wikipedia.

If you Dynamics NAV 2018 service will not start (or actually shuts down immediately when you try to start it), and you get something like this in your Windows Event Viewer (App Name, object ID and/or Name can probably be different ones):

Message: <ii>An error occurred while applying changes from the 'Payment and Reconciliation Formats (DK) by Microsoft 1.0.20348.0' app to the application object of type 'PageExtension' with the ID '13623'. The error was: InvalidOperationException - Metadata delta application failed due to the following error(s): The metadata object IncomingDocAttachFile was not found.</ii>

…your installation is FUBAR (or at least I don’t know how to repair it easily).

PowerShell cannot uninstall/unpublish the App when no Service Tier is running – so that is not an option.

Also I was not able to Google a solution, but here is what I did to make the service tier run again:

  • Take a fresh backup, and make sure nobody will open NAV until you say OK (it will be possible as soon as we get the Service Tier running again).
  • Export all your objects to text and locate (search for) the (probably page) object with the metadata object that could not be found (i.e. “IncomingDocAttachFile” in my example). I found it in Page Object 25.
  • Export the (Page) Object to a FOB-file (just so you have it).
    Overwrite/reimport the (Page) Object from a backup without your latest changes (be warned – if this is a table object, this will empty the table – so make sure to preserve the data somehow).
  • Redo your changes to the object without messing with theΒ metadata object that could not be found (i.e. “IncomingDocAttachFile” in my example.

Test that everything is ok, before letting anyone work again.

NOTE: I’ve not tried this with a table object, only a page object – so I’m not even sure this error can occur on tables?

DISCLAIMER: This is probably unsupported by Microsoft and you should do this on your own risk. We will not be responsible for any problems, data loss or down time etc. you may discover/experience following this procedure, or after doing this procedure. You are on your own here – but hopefully this will help you and save you the effort of finding a solution yourself! πŸ™‚


2018-06-22 I did’nt quite nail the solution first time around, as the problem creped in again. So I change the solution to the right one πŸ™‚

Even Microsoft gets this wrong :-)

Microsoft Dynamics NAV logo

In Dynamics NAV events are also fired on temporary records – this is really a confusing design and can trigger various, hard to debug, but rather serious issues.

On one customer running NAV 2018 CU1, user group memberships was cleared randomly. We did’nt know exactly when, but in the end one of my Indian colleagues figured out it happened related to the “Export to a datafile” functionality.
I was pretty sure someone was doing a DELETEALL – but was it in our code or in the standard code? And exactly how/where?

Actually it was easily found.
I created a subscriber one the delete trigger in table 9001 / User Group Member – only with one line of code:

ERROR('STOP');

…and started the debugger.

Note that events are fired even if the table trigger is not executed (i.e. INSERT/DELETE/MODIFY/RENAME is called with FALSE).

The deletion of the group membership is caused by the select/deselect all companies on the “Export to a Datafile” page in NAV. The list of companies is build in a temporary company record and DELETEALL is used on it when you select or deselect the all companies flag.

Unfortunately there is a subscriber in Codeunit 2 called OnAfterCompanyDeleteRemoveReferences which does not check if it is actually called with a company beeing removed, or just called with a temporary record instance from somewhere.
So it cleans up anyway – removing actual reference data from still existing companies!

This shows very clear that non-self-explanatory functionality like events beeing called on temporary records should have been avoided by Microsoft when designing this.
After all the goal of the development environment and -language should be to help developers write correct code – not to trap them into creating bugs.

If I had to redesign this functionality I would make it an function trigger property (default off) if the subscriber should run on temporary record instances.
Or at least let a subscriber parameter tell if it is temporary or not (not that this would make it easier to check, but it would remind you about checking it every time you created a subscriber πŸ™‚ ).

To me the current functionality is wrong, people are getting bitten by this. It is illogical design and even if you tried it once or even multiple times (and my guess is that you have if you are writing event subscribers), you’ll probably forget it and do it again in the future.

At least we know we are not alone – Microsoft C\AL developers are actually also getting bitten by this :-).

Please note – this bug is not only emptying the 9001 / User Group Member table, but other tables as well: User Group Access Control, Application Area Setup, Custom Report Layout and Repor tLayout Selection.

By the way: The correct fix (introduced in NAV 2018 CU2) is to make these lines the first two lines in Codeunit 2, OnAfterCompanyDeleteRemoveReferences:

IF Rec.ISTEMPORARY THEN
  EXIT;
[…]