{"record":{"id":"a8cc4f4e44a84b7c","repo":"unoplatform/uno","slug":"couldn-t-read-the-static-field-named-libraries-in","errorCode":null,"errorMessage":"Couldn't read the static field named _libraries in GLibrary","messagePattern":"Couldn't read the static field named _libraries in GLibrary","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.UI.WebView.Skia.X11/X11NativeWebView.cs","lineNumber":103,"sourceCode":"\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}\n\t\t\t};","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.UI.WebView.Skia.X11/X11NativeWebView.cs#L85-L121","documentation":"Third link in the same GLibrary patch chain: the '_libraries' field is found but its static value is null at the time of the call, so field.GetValue(null) returns null and the code throws NullReferenceException. GLibrary._libraries is lazily populated; if the patch runs before WebKitGtk# has initialized that cache (or after a version changed initialization timing), the value is still null.","triggerScenarios":"The '_libraries' static field exists but is null when patched — either because GLibrary static construction hasn't run yet (no WebKit type touched), or because a newer WebKitGtkSharp initializes the cache on first use rather than at type init.","commonSituations":"First navigation triggering the patch before any WebKitGtk# API has been touched; a WebKitGtkSharp version that defers _libraries population; running under a host that changed static-init ordering.","solutions":["Touch a WebKitGtk# API before the patch to force GLibrary static initialization (e.g. reference WebKit.Global or a GTK type).","Pin the WebKitGtkSharp version where _libraries is populated at type-init.","Update the patch to initialize _libraries when null rather than throw."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var f = asm.GetType(\"GLibrary\")?.GetField(\"_libraries\", BindingFlags.NonPublic | BindingFlags.Static);\nbool populated = f?.GetValue(null) is not null;","typeGuard":"static bool GLibraryLibrariesPopulated(Assembly asm) { var f = asm.GetType(\"GLibrary\")?.GetField(\"_libraries\", BindingFlags.NonPublic | BindingFlags.Static); return f?.GetValue(null) is not null; }","tryCatchPattern":null,"preventionTips":["Touch a WebKitGtk# API before navigation to force GLibrary static init.","Pin the WebKitGtkSharp version whose _libraries is populated at type-init.","Avoid HttpRequestMessage navigation on X11 to sidestep the 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"}