Cannot use the #[Export] attribute in C#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sandmor

I have a Node attached with the following script:

using Godot;
using System;

public class Stats : Node
    public int max_health = 1;

The script is defined as C# but anytime that I try to run the game I get in the MSBuild tab:

Stats.cs(6,5): Preprocessor directive expected

So, I get an error in the #Export declaration, I have been using C# in this project without any problem which is why this is unexpected.
So, can someone please help me with this? I’m on Linux also.

:bust_in_silhouette: Reply From: omggomb

You need to remove the # in #[Export], so it looks like this: [Export].

# in C# is used to declare preprocessor directives, hence the error message says that it expects such a directive.

Thank you, I really was stuck with this.

sandmor | 2021-08-07 18:08