Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Error function doesn’t work #598

Closed
bernatagulloesbrina opened this issue Jul 10, 2022 · 10 comments
Closed

C# Error function doesn’t work #598

bernatagulloesbrina opened this issue Jul 10, 2022 · 10 comments
Labels
issue: bug Confirmed as a bug in TE3
Milestone

Comments

@bernatagulloesbrina
Copy link

Hello,
I watched with great interest your presentation at SQLBits 2020, particularly the part to hack the script adding methods and classes at the end. I tried adding a class at the end of the script with the extra } and { and the end but to my surprise these where not expected. I managed to get an execution by just adding the class, but then I'm getting an error when using the Error( ) function, as follows. It is odd because passing a single string should be enough isn't it? I tried passing some integer and a boolean and now I'm getting a null reference error that I always struggle with.

Object Type Message Line Column
Error There is no argument given that corresponds to the required formal parameter 'suppressHeader' of 'ScriptHost.Error(string, int, bool)' 85 29

@otykier
Copy link
Collaborator

otykier commented Jul 10, 2022

The script engine in TE3 allows you to define types and methods without the hack. In fact, the hack won’t work at all, as Roslyn will not compile the script if there are unmatching brackets.

class MyClass
{
    public void SayHello()
    {
        Info("Hello");
    }
}

var myClassInstance = new MyClass();
myClassInstance.SayHello();

There is a bug with Error and a few other global script methods in 3.3.2 (this is also why multiple people experienced issues with macros not working). Fix coming soon!

@otykier otykier changed the title Adding Classes at the end of the script C# Error function doesn’t work Jul 10, 2022
@otykier otykier added the issue: bug Confirmed as a bug in TE3 label Jul 10, 2022
@otykier otykier added this to the 3.3.3 milestone Jul 10, 2022
@bernatagulloesbrina
Copy link
Author

oh so the behaviour is different in TE2 ? thanks for the quick update and looking forward to the fix! I'll be presenting on c# scripts in september 😁

@otykier
Copy link
Collaborator

otykier commented Jul 10, 2022

Yes, it’s different. TE3 uses Roslyn, which is faster, more secure and enables the use of new C# 10 language features. This is part of the reason why we upgraded TE3 to use .NET 6.

TE2 uses the old CodeDomProvider for scripting, but this is deprecated these days and only supports language features up to C# 6.

@bernatagulloesbrina
Copy link
Author

I think I understand the reasons, but at the same time a bit sad that there will be now scripts for TE3 and scripts for TE2. And some (most probably) that will run on both.

@otykier
Copy link
Collaborator

otykier commented Jul 10, 2022

Yes, it was a priority for us to get TE3 to use Roslyn because of the other features it offers (better IntelliSense, etc.). But the plan is that TE2 will also use Roslyn eventually, thus ensuring that scripts work similar in both tools.

@bernatagulloesbrina
Copy link
Author

oh, glad to hear that!

@bernatagulloesbrina
Copy link
Author

I just read that you can also use Rosylin in TE2, right? Will the behaviour be the same then?
https://github.com/TabularEditor/TabularEditor/releases/tag/2.12.2
however the link with more information seems to be broken

@bernatagulloesbrina
Copy link
Author

just managed to set it up -- I still need the extra curly brackets but now the behaviour is much closer to TE3

@otykier
Copy link
Collaborator

otykier commented Jul 11, 2022

Yep, we don't want to ship the Roslyn compiler with TE2, as that will tremendously increase the footprint, and one of the reasons why people love TE2 is that it is so lightweight. Instead, we will make sure that you can define methods and types just like you can in TE3, but if you want the new C# 10 language features, you'll have to manually configure the Roslyn compiler as you did (more information link should point here.

@otykier
Copy link
Collaborator

otykier commented Jul 16, 2022

Issue with Error and other global script methods fixed in 3.3.3.

@otykier otykier closed this as completed Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Confirmed as a bug in TE3
Development

No branches or pull requests

2 participants