You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A Char passed to an Integer parameter of another object's method fails at run time: "Unable to convert from System.Char to System.Int32" #8374
1. Describe the bug
AL converts a Char to Integer implicitly. When the Char argument goes to a method of another object (called through Invoke with an object[]), the compiler puts the .NET char in the argument array without converting it to int, and the callee fails at run time when it converts its arguments. There is no compile-time diagnostic, and the server compiles the generated C#. A call to a procedure of the same object is a direct C# call and works.
2. To Reproduce
Steps to reproduce the behavior:
Create an app ("runtime": "15.0") with the two codeunits below.
Publish it to a Business Central 29 sandbox.
Run codeunit 50102 (e.g. add &codeunit=50102 to the web client URL).
Optionally, build with alc /generatecode+ and open bin/COD50102.cs in the .app to see the generated C#.
3. Expected behavior Take receives 65 and shows it. The argument should be converted to the parameter's type before it is put in the argument array, as the compiler already does for an assignment to an Integer:
Error at run time (observed in our app, whose generated code has exactly this pattern; the repro above generates the same line):
Unable to convert from System.Char to System.Int32.
The same generated code (not run) appears for a character of a Text variable (new object[] { this.source[1 - 1] }) and for a Char variable (new object[] { this.character }). A call to a procedure of the same object is not affected (base.Parent.TakeLocal(this.source[1 - 1]) is a direct call with the implicit C# conversion).
Workaround: assign the Char to an Integer variable first and pass the variable.
5. Versions:
AL Language: 18.1.2842859 (compiler alc.exe 18.1.43.24897)
Visual Studio Code: 1.142.0
Business Central: online sandbox, version 29 (platform 29.0.57071.0)
List of Visual Studio Code extensions that you have installed: not involved. The repro was built with the command-line compiler (alc.exe from the AL Language extension's bin folder), outside Visual Studio Code.
Operating System:
Windows
Linux
MacOS
Final Checklist
Please remember to do the following:
Search the issue repository to ensure you are reporting a new issue
Reproduce the issue after disabling all extensions except the AL Language extension
Simplify your code around the issue to better isolate the problem
Activity