X++ "invalid token" message when calling c# library (How to call the method correctly)

Viewed 1001

I'm trying to create an excel file using x++ code. However, I'm getting the compile error "invalid token" even though intellisense all works correctly when typing out the code. What is the correct way to call the Add() method in x++ for the OfficeOpenXml classes (and in general c# librarys like this?)

using OfficeOpenXml;
using OfficeOpenXml.ExcelPackage;
using OfficeOpenXml.ExcelRange;

class ExcelTestClass
{
    public static void main(Args _args)
    {
        using (ExcelPackage excel = new ExcelPackage())
        {
            excel.Workbook.Worksheets.Add("Worksheet1");

            
        }
    }
}

enter image description here

2 Answers

To add some background detail from Martin Dráb's answer: x++ does not support working with properties of objects in C#/.Net libraries directly. You have to use set and get methods to access those, which is why excel.getWorkbook() works and excel.Workbook does not.

Some other restrictions are

  • you need to use fully qualified names
  • generics are not supported

Additional information can be found at .NET Interop from X++

Related