TabularEditor / TabularEditor3

Bug reports, feature requests, discussion and documentation for Tabular Editor 3 (commercial version).
61 stars 7 forks source link

#load directive runs, but causes a save error #1185

Closed samaguire closed 5 months ago

samaguire commented 5 months ago

Description

I've created a simple csx (C# script) file which contains a single class. I can load the csx file and utilise the class, however, I get an error (without details) when I try to save the macro.

TE3 Macro

#load "C:\Users\maguires\AppData\Local\TabularEditor3\CustomClasses.csx"

CustomClass.CreateCT("tst", "{0}")

C# Script

#r "Microsoft.VisualBasic"

using Microsoft.VisualBasic;

// *** The below public classes are common across scripts ***
public static class CustomClass
{

    // this is an example one
    public static Table CreateCT(string tableName, string tableExpression)
    {

        return Model.AddCalculatedTable(
            name: tableName,
            expression: tableExpression
            );

    }

}

Tabular Editor 3 Version

3.12.0

Screenshots

image

Steps to Reproduce

No response

Expected behavior

The macro saves and can be used again in the future

Crash Report

No response

Windows Version

Windows 10 Pro (22H2)

samaguire commented 5 months ago

NB: I noticed the missing ';' at the end of the last line in my code. I fixed for this, but the result is the same.

otykier commented 5 months ago

Hi @samaguire

We don't officially support the use of the #load preprocessor directive, so this is not a bug per se. The reason that it works in scripts is that we use Roslyn's Scripting API, where as for macros, the code is compiled into a reusable module. The latter does not support the use of #load. Moreover, it's not clear how changes made to the referenced .cs/.csx files, should cause recompilation of this module.

So for now, you'll have to find a workaround, such as copying the referenced code into your script before saving it as a macro. You'll also find that the #load directive won't work at all in TE2.

We're happy to list this as a feature request, as we certainly see the benefit of being able to reuse code this way, but it'll have to be prioritized among the other items in our backlog.