Empty "Case of" Statements fail in c# compiler on Servicetier while publish Extension
Given an Case statement with no acutal case defined like the following:
Case True Of
// no actual case
else begin
Message('will this work?');
end;
The AL compiler in VSC (and also the old compiler in C/SIDE) accepts this. When it comes to deployment of the app to the Service Tier server the system will fail with something like:
error CS0151: A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type
Expected behavior AL Compiler fails to compile the app. if no actual case statement is present.
Versions:
- AL Langauge: 2.0.43900
- Business Central: 2.0.43900
Hi, I'm unable to reproduce your issue using the latest AL extension (2.0.56865) with BC sandbox version US Dynamics NAV 13.1 (26534).
Can you try to update your tooling and retry please?
I'll give it a try and come back to you. sure.
please share exact code lines to replicate Compiler error.
Hi,
So I did some test with different Versions: I'm using AL Langugage 2.1.70607 in VSC and I'm running against:
W1 13.0 (24630) : I get the error mentioned error W1 14.0 (26561) : seems to accept it
Code to replicate:
make an AL:Go! and replace Message('App published: Hello world'); with
Case rec.Blocked of
// nothing here;
// nope ;
// nada;
else
Message('This publishes in 26561 not in 24630');
end;
I must admit that the Case true of also works the "older" version. So it has a relation to the option maybe.
Hi @KristofKleinm, I'll close this issue because it works in a later version as you state. Thanks for reporting this issue.
@JohanStenberg100
I'm having the same issue, I can provide more details: If you use a "Case of" statement with a variable of type Option. In case there are no cases inside the statement, Build is fine, it's compiled successfully but the deployment of the app throws this error:
The request for path XXXapps?SchemaUpdateMode=synchronize failed with code 422. Reason: c:\ProgramData\Microsoft\Microsoft Dynamics NAV\130\Server\MicrosoftDynamicsNavServer$XXX\source\PageExtension\PageExtension50100.cs(114,25) : error CS0151: A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type
Here is the code (added to the hello-word project):
pageextension 50100 CustomerListExt extends "Customer List"
{
trigger OnOpenPage();
var
loptDays: option Mon,Tue,Wed,Thu,Fri,Sat,Sun;
begin
Message('App published: Hello world');
case loptDays of
end;
end;
}
I'm using AL extension (2.1.79379) and deploying on Business Central on-premise CU3 (runtime 2.3) and also I tried same AL extension, deploying on MS Cloud Sandbox (runtime 2.2), with the same result.
Thanks @babak2000ir, I'll re-open the issue and we'll take a look.
Hi @babak2000ir, sorry for the long wait. On our master branch your issue doesn't reproduce. I will close this issue now, please comment if your still running into this on the latest version of BC. Thanks!