如何使用Visual Studio 2017构建Gtk#/ Mono应用程序

时间:2019-03-08 02:46:27

标签: visual-studio visual-studio-2017 mono gtk#

好的,我完全不知所措。在过去的两个小时中,我一直在与Gtk#和Mono纠缠不清,但是却一无所获。

我已经使用链接available on Mono's website安装了Mono以及GtkSharp。我还使用MSYS2从他们的网站上安装了Gtk。

我的应用程序的完整代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Gtk;

namespace InstallCheck {
    public class GtkSharpTest {
        public static void Main() {
            Application.Init();

            Window window = new Window("Hello Mono World");
            window.Show();

            Application.Run();
        }
    }
}

在Visual Studio中,我已经添加了对glib-sharp.dll和gtk-sharp.dll的引用。它的构建很好,但是当我使用mono InstallCheck.exe运行它时,出现此错误:

Unhandled Exception:
System.DllNotFoundException: libglib-2.0-0.dll
  at (wrapper managed-to-native) GLib.Marshaller.g_utf16_to_utf8(char*,intptr,intptr,intptr,intptr&)
  at GLib.Marshaller.StringToPtrGStrdup (System.String str) [0x00034] in <d973ca9f8b494b789fba7fe0ad040b14>:0
  at GLib.Global.set_ProgramName (System.String value) [0x00001] in <d973ca9f8b494b789fba7fe0ad040b14>:0
  at Gtk.Application.SetPrgname () [0x0000d] in <35293b6aa2744433b0e2f41f34e699d5>:0
  at Gtk.Application.Init () [0x00001] in <35293b6aa2744433b0e2f41f34e699d5>:0
  at InstallCheck.GtkSharpTest.Run () [0x00001] in <f385106059954ecb8802348d7a6abfe1>:0
  at InstallCheck.GtkSharpTest.Main (System.String[] args) [0x00027] in <f385106059954ecb8802348d7a6abfe1>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: libglib-2.0-0.dll
  at (wrapper managed-to-native) GLib.Marshaller.g_utf16_to_utf8(char*,intptr,intptr,intptr,intptr&)
  at GLib.Marshaller.StringToPtrGStrdup (System.String str) [0x00034] in <d973ca9f8b494b789fba7fe0ad040b14>:0
  at GLib.Global.set_ProgramName (System.String value) [0x00001] in <d973ca9f8b494b789fba7fe0ad040b14>:0
  at Gtk.Application.SetPrgname () [0x0000d] in <35293b6aa2744433b0e2f41f34e699d5>:0
  at Gtk.Application.Init () [0x00001] in <35293b6aa2744433b0e2f41f34e699d5>:0
  at InstallCheck.GtkSharpTest.Run () [0x00001] in <f385106059954ecb8802348d7a6abfe1>:0
  at InstallCheck.GtkSharpTest.Main (System.String[] args) [0x00027] in <f385106059954ecb8802348d7a6abfe1>:0

我不知道这意味着什么。我已经用Google和Bing了,结果出现了,但是他们提供的解决方案不起作用。是的,Mono在我的路径中,是的,GtkSharp也在我的路径中。我究竟做错了什么?这是GTK错误,单声道错误还是VS2017错误?我如何解决它?预先感谢。

编辑:我现在已经尝试按照this issue的建议对Gtk进行降级,但这仍然没有效果。

1 个答案:

答案 0 :(得分:0)

您可以使用nuget包GtkSharp.Win32在Visual Studio 2017中创建Gtk应用程序。 https://github.com/jhojen26/GtkSharpTest