I'm trying to embed C# scripts into my C++ Game Engine Project, so I followed this example which uses mono: gist-link. The code itself runs fine, I can access the methods of the class, but I have a throw whenever I try to call the Console.WriteLine() function. It seems I can't use System functions inside my scripts.
Here is the log for the throw for the function:
Dog.cs:
public class Dog
{
static public void Type()
{
Console.WriteLine("a Dog!");
}
...
}
Error log:
Running the static method: Dog:Type()
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: System.Native assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
at Interop+Sys..cctor () [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0
--- End of inner exception stack trace ---
at System.IO.FileSystem.FileExists (System.ReadOnlySpan`1[T] fullPath, System.Int32 fileType, Interop+ErrorInfo& errorInfo) [0x00007] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.IO.FileSystem.DirectoryExists (System.ReadOnlySpan`1[T] fullPath, Interop+ErrorInfo& errorInfo) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.IO.FileSystem.DirectoryExists (System.ReadOnlySpan`1[T] fullPath) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.IO.Directory.Exists (System.String path) [0x0001e] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.TermInfoDriver.SearchTerminfo (System.String term) [0x00044] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.TermInfoDriver..ctor (System.String term) [0x0004b] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.ConsoleDriver..cctor () [0x0004d] in <de882a77e7c14f8ba5d298093dde82b2>:0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.Console..cctor () [0x0007d] in <de882a77e7c14f8ba5d298093dde82b2>:0
--- End of inner exception stack trace ---
at Dog.Type () [0x00000] in <f155b242589444d6a2f6baf230b1c326>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: System.Native assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
at Interop+Sys..cctor () [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0
--- End of inner exception stack trace ---
at System.IO.FileSystem.FileExists (System.ReadOnlySpan`1[T] fullPath, System.Int32 fileType, Interop+ErrorInfo& errorInfo) [0x00007] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.IO.FileSystem.DirectoryExists (System.ReadOnlySpan`1[T] fullPath, Interop+ErrorInfo& errorInfo) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.IO.FileSystem.DirectoryExists (System.ReadOnlySpan`1[T] fullPath) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.IO.Directory.Exists (System.String path) [0x0001e] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.TermInfoDriver.SearchTerminfo (System.String term) [0x00044] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.TermInfoDriver..ctor (System.String term) [0x0004b] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.ConsoleDriver..cctor () [0x0004d] in <de882a77e7c14f8ba5d298093dde82b2>:0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.Console..cctor () [0x0007d] in <de882a77e7c14f8ba5d298093dde82b2>:0
--- End of inner exception stack trace ---
at Dog.Type () [0x00000] in <f155b242589444d6a2f6baf230b1c326>:0
In this throw I get that System.DllNotFoundException was called, but I have called
mono_set_dirs("/usr/lib/", "/etc/");
to set mono to find the dlls at /usr/lib/mono/4.5/. The dll is there so I don't understand.
I am running this on Ubuntu 22.04 LTS, I have mono installed locally and linked to my project using the .so file.
I have tried moving the System.dll from /usr/lib/mono/4.5/ to my repository and link it manually, but that didn't change anything.
To call manually I did:
mono_domain_assembly_open(domain, "System.dll");