我一整天都在尝试让GTK#在Windows Server 2008 R2 x64的Visual Studio 2010上工作,以便我可以开始编写漂亮的跨平台GUI应用程序,但我对C#还比较陌生,遇到了很多麻烦。
我安装了包含GTK#的最新的Mono for Windows。我还安装了一个Mono 2.10.8配置文件,将其作为我的项目目标框架,大致按照这里的指南:http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/。
我创建了一个新的Windows Forms应用程序,并删除了对Windows Forms的引用,添加了对GTK#的引用,大致按照这里的指南:http://jrwren.wrenfam.com/blog/2008/11/01/gtk-in-visual-studio-2008-on-vista-x64/。
我还添加了对gtk-dotnet的引用,除了那个指南中的引用。
这是我的应用程序的完整代码:using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using Gtk;
namespace GridToGo
{
static class Program
{
[STAThread]
static void Main()
{
Application.Init();
Window myWin = new Window("My first GTK# Application! ");
myWin.Resize(200, 200);
myWin.Destroyed += new EventHandler(myWin_Destroyed);
Label myLabel = new Label();
myLabel.Text = "Hello World!!!!";
myWin.Add(myLabel);
myWin.ShowAll();
Application.Run();
}
static void myWin_Destroyed(object sender, EventArgs e)
{
Application.Quit();
}
}
}
无论我使用哪种配置尝试运行此程序,都会出现以下异常:
System.TypeInitializationException was unhandled
Message=The type initializer for 'Gtk.Application' threw an exception.
Source=gtk-sharp
TypeName=Gtk.Application
StackTrace:
at Gtk.Application.Init()
at GridToGo.Program.Main() in F:\visual-studio\GridToGo\GridToGo\Program.cs:line 13
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.DllNotFoundException
Message=Unable to load DLL 'glibsharpglue-2': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source=glib-sharp
TypeName=""
StackTrace:
at GLib.Thread.glibsharp_g_thread_supported()
at GLib.Thread.get_Supported()
at Gtk.Application..cctor()
InnerException:
我无法弄清楚如何让它找到那个dll文件!我甚至尝试将4个DLL文件复制到解决方案中几乎每个文件夹中,使用以下名称:glibsharpglue-2
glibsharpglue-2.dll
glibsharpglue-2.o
glibsharpglue-2.o.dll
!我甚至尝试安装GTK全套包并将其bin文件夹添加到系统路径中,然后将相同的4个dll文件复制到该文件夹中,但都没有成功。
对于我的疯狂问题有什么建议吗?我感觉我在这里漏掉了什么重要的东西。 >_<