Unable to load DLL 'libgtk-win32-2.0-0.dll' RRS feed

  • Question

  • User47237 posted


    I just install Xamarin and make a Gtk# 2.0 Project when i try to execute i get error : Unable to load DLL 'libgtk-win32-2.0-0.dll' as describe here http://forums.xamarin.com/discussion/2091/cannot-run-gtk-project i install mono runtime 3.4.0 and set as default .net runtime in Xamarin options now i can execute my Gtk# project in Xamarin with or without debugging

    but if i execute exe outside of Xamarin studio i get error message :

    System.DllNotFoundException was unhandled Message=Unable to load DLL 'libgtk-win32-2.0-0.dll': The specified procedure could not be found. (Exception from HRESULT: 0x8007007F)

    thanks for help

    Thursday, April 10, 2014 3:10 PM

All replies

  • User47237 posted

    forgot my configuration : windows 7 64 bits

    Thursday, April 10, 2014 6:08 PM
  • User28 posted

    Check your project's compiler options are set to the "x86" platform. GTK# on Windows does not support 64-bit yet.

    Thursday, April 10, 2014 9:33 PM
  • User47237 posted

    my compiler options are already set to "x86" still dont work

    Friday, April 11, 2014 8:19 AM
  • User28 posted

    Can you confirm that the value of IntPtr.Size is 4 when running your program on .NET?

    I'd also suggest that you use CheckWindowsGtk from MonoDevelop's IdeStartup.cs. You can call this in your Main method before calling GTK# and will try to fix potential problems with dll search paths.

    Tuesday, April 15, 2014 4:47 PM
  • User47237 posted


    I put a message to verify the IntPtr.Size and it is 4 as you expect

    I add the CheckWindowsGtk function.

    CheckWindowsGtk found keys SOFTWARE\Xamarin\GtkSharp\InstallFolder, SOFTWARE\Xamarin\GtkSharp\Version and call SetDllDirectory("C:\Program Files (x86)\GtkSharp\2.12\bin")

    now I get another exception :

    Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Mono.Posix, Version=, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. The system cannot find the file specified.

    I try to add "c:\Program Files (x86)\Mono-3.2.3\lib\mono\4.0" to the path but it does'nt work

    I also install Xamarin on a windows 7 32 bits and everything work

    I continue to search by myself

    Thanks for help I hope we found a solution

    Wednesday, April 16, 2014 2:51 PM
  • User47237 posted

    I add AssemblyResolve function as a temporary solution

    public static void Main (string[] args) { CheckWindowsGtk(); AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve; Application.Init(); MainWindow win = new MainWindow(); win.Show(); Application.Run(); } static Assembly AssemblyResolve(object sender, ResolveEventArgs args) { if (args.Name == "Mono.Posix, Version=, Culture=neutral, PublicKeyToken=0738eb9f132ed756") { return LoadAssemblyFrom(@"c:\Program Files (x86)\Mono-3.2.3\lib\mono\4.0\Mono.Posix.dll"); } return null; }

    Wednesday, April 16, 2014 5:12 PM
  • User47237 posted

    the error loading Mono.Posix.dll from mono runtime come because mono runtime is not in the GAC

    finally I select microsoft .net runtime and call CheckWindowsGtk() before Application.Init()

    everything work fine like this

    public static void Main (string[] args) { CheckWindowsGtk(); Application.Init(); MainWindow win = new MainWindow(); win.Show(); Application.Run(); } static bool CheckWindowsGtk () { string location = null; Version version = null; Version minVersion = new Version (2, 12, 22); using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Xamarin\GtkSharp\InstallFolder")) { if (key != null) location = key.GetValue (null) as string; } using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey (@"SOFTWARE\Xamarin\GtkSharp\Version")) { if (key != null) Version.TryParse (key.GetValue (null) as string, out version); } //TODO: check build version of GTK# dlls in GAC if (version == null || version < minVersion || location == null || !File.Exists (Path.Combine (location, "bin", "libgtk-win32-2.0-0.dll"))) { Console.WriteLine ("Did not find required GTK# installation"); // string url = "http://monodevelop.com/Download"; // string caption = "Fatal Error"; // string message = // "{0} did not find the required version of GTK#. Please click OK to open the download page, where " + // "you can download and install the latest version."; // if (DisplayWindowsOkCancelMessage ( // string.Format (message, BrandingService.ApplicationName, url), caption) // ) { // Process.Start (url); // } return false; } Console.WriteLine ("Found GTK# version " + version); var path = Path.Combine (location, @"bin"); Console.WriteLine ("SetDllDirectory(\"{0}\") ", path); try { if (SetDllDirectory (path)) { return true; } } catch (EntryPointNotFoundException) { } // this shouldn't happen unless something is weird in Windows Console.WriteLine ("Unable to set GTK+ dll directory"); return true; }

    Thursday, April 17, 2014 2:22 PM
  • User47237 posted

    SetDllDirectory source [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true)] [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)] static extern bool SetDllDirectory (string lpPathName);

    Thursday, April 17, 2014 2:40 PM
  • User160521 posted

    just want to thank la_beuze for this solution. The error seems to occur on computers that had different gtk-sharp versions installed in the past. I got this error on windows 7 (32 and 64) and windows 10 computers who had previously installed gtk-sharp-2.12.10.win32.msi and then were updated with gtk-sharp-2.12.26.msi. The registry and path values seemed fine on all machines, but somehow the wrong libraries were loaded (I assume from gtk2-runtime-2.24.10-2012-10-10) which is why I got the Error Unable to load DLL 'libgtk-win32-2.0-0.dll'. This dll was present in both gtk-sharp and gtk2-runtime, but I guess in gtk2-runtime there are some missing dependencies which can also cause this error.

    Also have to add that dependency walker didn't help me at all in this case, it just seems too outdated. Is there a c# method that shows me which dlls are actually (tried to be) loaded by my program?

    So, after some struggling, la_beuze's last 2 posts made my day. Thanks again.

    Monday, September 21, 2015 3:06 PM