{"record":{"id":"80c4103a77ea1155","repo":"unoplatform/uno","slug":"couldn-t-find-glibrary-in-webkitgtksharp","errorCode":null,"errorMessage":"Couldn't find GLibrary in WebKitGtkSharp","messagePattern":"Couldn't find GLibrary in WebKitGtkSharp","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.UI.WebView.Skia.X11/X11NativeWebView.cs","lineNumber":99,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\n\t\t\t// webkit2gtk-4.1 adds support for exposing libsoup objects, most importantly in webkit_uri_request_get_http_headers.\n\t\t\t// Gtk# by default loads libwebkit2gtk-4.0 (+ libsoup-2.0), but we want libwebkit2gtk-4.1 (+ libsoup-3.0), so what\n\t\t\t// we do is that before WebKitGtk# makes its dlopen calls, we load libwebkit2gtk-4.1 and put it where the handle to\n\t\t\t// libwebkit2gtk-4.0 will be expected to be, so that when WebKitGtk# attempts to dlopen(libwebkit2gtk-4.0), it will\n\t\t\t// find the handle already there and will just use it instead.\n\t\t\tif (!NativeLibrary.TryLoad(\"libwebkit2gtk-4.1.so\", typeof(X11NativeWebView).Assembly, DllImportSearchPath.UserDirectories, out var webkitgtk41handle))\n\t\t\t{\n\t\t\t\tif (typeof(X11NativeWebView).Log().IsEnabled(LogLevel.Error))\n\t\t\t\t{\n\t\t\t\t\ttypeof(X11NativeWebView).Log().Error($\"libwebkit2gtk-4.1 was not found. Attempting to call {nameof(ProcessNavigation)} with an {nameof(HttpRequestMessage)} instance will crash the process.\");\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tAssembly assembly = Assembly.Load(\"WebKitGtkSharp\");\n\t\t\t\tType glibraryType = assembly.GetType(\"GLibrary\") ?? throw new NullReferenceException(\"Couldn't find GLibrary in WebKitGtkSharp\");\n\t\t\t\tType libraryType = assembly.GetType(\"Library\") ?? throw new NullReferenceException(\"Couldn't find Library in WebKitGtkSharp\");\n\t\t\t\tobject webkitLibraryEnum = Enum.ToObject(libraryType, 11);\n\t\t\t\tFieldInfo field = glibraryType.GetField(\"_libraries\", BindingFlags.NonPublic | BindingFlags.Static) ?? throw new NullReferenceException(\"Couldn't find a field named _libraries in GLibrary\");\n\t\t\t\tobject libraries = field.GetValue(null) ?? throw new NullReferenceException(\"Couldn't read the static field named _libraries in GLibrary\");\n\t\t\t\tvar setItemMethod = libraries.GetType().GetMethod(\"set_Item\") ?? throw new NullReferenceException(\"Couldn't find a method named set_Item in _libraries\");\n\t\t\t\tsetItemMethod.Invoke(libraries, [webkitLibraryEnum, webkitgtk41handle]);\n\t\t\t\t_usingWebKit2Gtk41 = true;\n\t\t\t}\n\n\t\t\tif (!WebKit.Global.IsSupported)\n\t\t\t{\n\t\t\t\t_initException = new PlatformNotSupportedException(\"libwebkit2gtk-4.0 is not found. Make sure that WebKit2GTK 4.0 and GTK 3 are installed. See https://aka.platform.uno/webview2 for more information\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tGLib.ExceptionManager.UnhandledException += args =>\n\t\t\t{\n\t\t\t\tif (typeof(X11NativeWebView).Log().IsEnabled(LogLevel.Error))","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.UI.WebView.Skia.X11/X11NativeWebView.cs#L81-L117","documentation":"X11NativeWebView (Skia WebView on Linux/X11) reflects into the WebKitGtkSharp assembly to patch GLibrary so that libwebkit2gtk-4.1.so is pre-loaded before WebKitGtk# dlopens 4.0. It does `Assembly.Load(\"WebKitGtkSharp\").GetType(\"GLibrary\")` and throws NullReferenceException when the type is absent. This is a coupling to a private implementation detail of WebKitGtkSharp: if the package is upgraded/changed so that GLibrary is renamed or removed, the patch can no longer find its anchor.","triggerScenarios":"A WebKitGtkSharp version is loaded whose public/internal structure no longer exposes a type literally named 'GLibrary' (the bootstrap class), while libwebkit2gtk-4.1.so IS present (the else-branch is taken).","commonSituations":"Updating the WebKitGtkSharp NuGet dependency on a distro; running on a Linux distribution whose packaged WebKitGtk# differs; trimming/IL-linking that strips the GLibrary type.","solutions":["Pin the WebKitGtkSharp package version that ships the GLibrary type that X11NativeWebView expects (check the referenced version in the Skia.X11 WebView add-in csproj).","Ensure the correct libwebkit2gtk-4.1.so is installed so the patch path still resolves; if 4.1 is missing the code logs an error and proceeds to the 4.0 path instead (no throw here).","If you maintain the add-in, update the reflection anchor (type/field/method names) to match the installed WebKitGtkSharp internals."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate the WebKitGtkSharp internals surface before relying on the patch\nvar asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == \"WebKitGtkSharp\");\nbool gLibraryPresent = asm?.GetType(\"GLibrary\") is not null;","typeGuard":"static bool WebKitGtkSharpHasGLibrary() => AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == \"WebKitGtkSharp\")?.GetType(\"GLibrary\") is not null;","tryCatchPattern":"try { NavigateWithHttpRequest(request); }\ncatch (NullReferenceException ex) when (ex.Message.Contains(\"GLibrary\")) { /* fall back to URI navigation */ }","preventionTips":["Pin the WebKitGtkSharp package version that matches X11NativeWebView's reflection anchors.","Install libwebkit2gtk-4.0 (and optionally 4.1) per the add-in docs.","Prefer URI navigation over HttpRequestMessage navigation to avoid the 4.1 patch path."],"tags":["x11","linux","webview","webkitgtk","reflection","native-interop"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}