{"record":{"id":"c12b8361c348d51e","repo":"unoplatform/uno","slug":"couldn-t-find-a-field-named-libraries-in-glibrary","errorCode":null,"errorMessage":"Couldn't find a field named _libraries in GLibrary","messagePattern":"Couldn't find a field named _libraries in GLibrary","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.UI.WebView.Skia.X11/X11NativeWebView.cs","lineNumber":102,"sourceCode":"\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))\n\t\t\t\t{\n\t\t\t\t\ttypeof(X11NativeWebView).Log().Error(\"GLib exception\", args.ExceptionObject as Exception);\n\t\t\t\t}","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.UI.WebView.Skia.X11/X11NativeWebView.cs#L84-L120","documentation":"Same reflection patch in X11NativeWebView: after locating the GLibrary type it fetches the private static field '_libraries' via reflection and throws NullReferenceException if that field name no longer exists. The whole block is monkey-patching WebKitGtk#'s internal library-handle cache to substitute the 4.1 handle for the 4.0 one. A WebKitGtkSharp internals rename of _libraries breaks the patch deterministically.","triggerScenarios":"GLibrary type resolves (so [44] didn't throw) but the private static field '_libraries' is missing — a WebKitGtkSharp version where the cache field was renamed or its backing changed.","commonSituations":"Bumping WebKitGtkSharp across a release that refactored its internal library registry; running against a distro-modified WebKitGtk# build.","solutions":["Pin the WebKitGtkSharp version whose internals match this reflection code (the version referenced by the add-in at the time it was written).","Update the reflection field name '_libraries' in X11NativeWebView to match the current WebKitGtkSharp source.","As a fallback path, let the code skip the 4.1 patch and rely on the libwebkit2gtk-4.0 path (only viable if 4.0 is installed and IsSupported is true)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var t = asm.GetType(\"GLibrary\");\nbool fieldPresent = t?.GetField(\"_libraries\", BindingFlags.NonPublic | BindingFlags.Static) is not null;","typeGuard":"static bool GLibraryHasLibrariesField(Assembly asm) => asm.GetType(\"GLibrary\")?.GetField(\"_libraries\", BindingFlags.NonPublic | BindingFlags.Static) is not null;","tryCatchPattern":null,"preventionTips":["Lock the WebKitGtkSharp version so its internal field names stay stable.","Track upstream WebKitGtk# internals when bumping the package.","Use URI navigation when only 4.0 is available to bypass the patch entirely."],"tags":["x11","linux","webview","webkitgtk","reflection","native-interop"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}