I am about to start development of a software project that should run on Linux and Windows if possible. As I already have some experience with C# I am eager to use it for this project. I assumed that with .NET Core 3 and GTK# 3.22 this shouldn't be a problem since .NET Core App should be cross-platform out of the box. GTK# - from my understanding - should work everywhere GTK+ in the same version is also available.
Why c#? Well I just like the language and there is an ECS Framework for c# I'd like to use.
So far I have setup a test Console App project in Visual Studio targeting .NET Core 3 and added an GTK# specific NuGet package.
I wrote a simple Hello World program for testing of the environment.
using System;
using Gtk;
namespace GTKTest
{
class Program
{
static void Main(string[] args)
{
Application.Init();
Window win = new Window("Hello GTK");
Label lbl = new Label("This is a test GTK App written with C# for GNU/Linux and Windows");
win.DeleteEvent += Win_DeleteEvent;
win.Add(lbl);
win.ShowAll();
Application.Run();
win.Dispose();
Console.Write("Press any key...");
Console.ReadKey();
}
private static void Win_DeleteEvent(object o, DeleteEventArgs args)
{
Application.Quit();
args.RetVal = true;
}
}
}
When I run this code from Visual Studio 2019 I get
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'Gtk.Application' threw an exception.
Source=GtkSharp
StackTrace:
at Gtk.Application.Init()
at GTKTest.Program.Main(String[] args) in D:\Workspace\VSRepos\C#\GTKTest\Program.cs:line 10
Inner Exception 1:
DllNotFoundException: Gtk
While searching for a solution I installed mono and GTK# for Windows from this page. The mono part shouldn't be necessary if I stick to .NET Core I think.
What am I missing? What am I doing wrong? Is what I'm trying to achieve even possible like I am imaging it? I'm also interested in some alternatives how to program cross-platform GUI-Software with C#. I stumbled upon electron.js but I heard it has some big Memory overhead and I'm not really into javascript. AvaloniaUI sounded interesting but I thought that the above approach would be better.
Edit: After adding msys path like suggested here in step 3 I get following error preceding the exception from above. The error states that the procedure entry point couldn't be found in the dll.
User contributions licensed under CC BY-SA 3.0