Problem with static properties using c#

Godot Version

Godot v4.2 with C# API


Hi everyone, I’m new in the Godot community ^^

I was trying to see what engine might be best to port an old Monogame (xna) project.
Trying to import the logic libraries into Godot, things went quite well. When ran from the Visual Studio or from the Godot editor there was no problem. But when export the project for Windows it ran but did not behave correctly.

I found that the problem came from a static property of a static class of a library that I was referencing from the godot project. For some reason when executing the exported program I was not receiving the values of that property.

The project structure it’s a little complex but in short it’s something like this:

Another Project (let’s call it Y)
=> Static Class
==> Static Property (let’s call it X)… This value changes

Godot Project (reference the project Y)
=> Script (c#)
==> Use the static property X from the project Y… in windows excecution is empty.

I don’t usually ask questions on blogs but this situation seemed quite strange to me. Does anyone know what could be happening?

How are you referencing the library from Godot?

From the Project on the Solution in the Visual Studio. Right click over the project, add reference and selected the other project

The Godot project Assembly generate a line like this:
<ProjectReference Include="MyOtherProject.csproj" />

That makes sense. That will work in VS and in the Godot editor, but when you export from Godot it’s actually using a separate, prebuilt binary. Can you build “MyOtherProject.csproj” into a DLL? I think you’re going to need to do so and then incorporate it using GDExtension. Maybe someone will correct me if there is an easier solution.

The export has a folder called “data_GodotProject_windows_x86_64” which has among other things the DLLS that I have referenced. Exception does not throw upon execution, it simply does not receive the values from the static properties. For example for a INT type, will always return 0.

I’m also going to try what you told me with GDExtension. Then I’ll tell the results ^^