Search code examples
axaptax++dynamics-365-operations

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


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


Solution

  • Of course, just as I give in and ask a question on SA I stumble on the answer while googling.

    The correct way to call it is following:

    excel.get_Workbook().get_Worksheets().Add("Worksheet1");
    

    From this post: https://community.dynamics.com/ax/f/microsoft-dynamics-ax-forum/178373/calling-visual-studio-c-classes-in-x/438484 Martin Dráb's answer.