{"record":{"id":"384daf6f909f872a","repo":"stride3d/stride","slug":"couldn-t-find-method-preloadlibrary-in","errorCode":null,"errorMessage":"Couldn't find method 'PreloadLibrary' in {nativeLibraryHelperType}","messagePattern":"Couldn't find method 'PreloadLibrary' in (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs","lineNumber":289,"sourceCode":"        var nativeLibraryHelperType = strideCoreAssembly.GetType(\"Stride.Core.NativeLibraryHelper\")\n            ?? throw new InvalidOperationException($\"Couldn't find type 'Stride.Core.NativeLibraryHelper' in {strideCoreAssembly}\");\n        var registerDependencyMethod = nativeLibraryHelperType.GetMethod(\"RegisterDependency\")\n            ?? throw new InvalidOperationException($\"Couldn't find method 'RegisterDependency' in {nativeLibraryHelperType}\");\n        foreach (var lib in nativeLibs)\n            registerDependencyMethod.Invoke(null, [lib]);\n    }\n\n    /// <summary>\n    /// Loads the listed native libs in Stride.Core.NativeLibraryHelper using reflection to avoid a compile time dependency on Stride.Core\n    /// </summary>\n    private static void LoadNativeDependencies(Dictionary<string, string> assemblyNameToPath, List<string> nativeLibs)\n    {\n        var strideCoreAssembly = Assembly.LoadFrom(assemblyNameToPath[\"Stride.Core\"])\n            ?? throw new InvalidOperationException(\"Couldn't find assembly 'Stride.Core' in restored packages\");\n        var nativeLibraryHelperType = strideCoreAssembly.GetType(\"Stride.Core.NativeLibraryHelper\")\n            ?? throw new InvalidOperationException($\"Couldn't find type 'Stride.Core.NativeLibraryHelper' in {strideCoreAssembly}\");\n        var preloadLibraryMethod = nativeLibraryHelperType.GetMethod(\"PreloadLibrary\")\n            ?? throw new InvalidOperationException($\"Couldn't find method 'PreloadLibrary' in {nativeLibraryHelperType}\");\n        foreach (var lib in nativeLibs)\n        {\n            var libName = Path.GetFileNameWithoutExtension(lib);\n            preloadLibraryMethod.Invoke(null, [libName, null]);\n        }\n    }\n\n    public class Logger : ILogger\n    {\n        private readonly object logLock = new();\n        private Action<LogLevel, string>? action;\n        public List<(LogLevel Level, string Message)> Logs { get; } = [];\n\n        public void SetupLogAction(Action<LogLevel, string> action)\n        {\n            lock (logLock)\n            {\n                this.action = action;","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs#L271-L307","documentation":"LoadNativeDependencies reflects for a 'PreloadLibrary' method on Stride.Core.NativeLibraryHelper and throws an InvalidOperationException if GetMethod returns null. The preloading contract (method invoked as PreloadLibrary(libName, null)) is not present on the restored Stride.Core assembly.","triggerScenarios":"nativeLibraryHelperType was found but has no 'PreloadLibrary' method with a bindable signature (renamed, internal, or parameter changes) in the restored Stride.Core version.","commonSituations":"Stride runtime upgraded ahead of the NuGetResolver reflection contract; custom Stride.Core forks without PreloadLibrary; strict trimming removing the method.","solutions":["Pin/restore the Stride runtime version the resolver was built against.","Verify the method on the actual DLL: typeof(NativeLibraryHelper).GetMethod(\"PreloadLibrary\", BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static).","Update the resolver to call the new preload API if you upgraded Stride intentionally.","Disable aggressive trimming/publish trimming for the assemblies being reflected over."],"exampleFix":"// before\npublishOptions.TrimMode = \"full\"; // trims PreloadLibrary away from Stride.Core\n// after\npublishOptions.TrimMode = \"partial\"; // or exclude Stride.Core from trimming","handlingStrategy":"try-catch","validationCode":"var t = Assembly.LoadFrom(strideCorePath).GetType(\"Stride.Core.NativeLibraryHelper\");\nif (t?.GetMethod(\"PreloadLibrary\") == null)\n    throw new InvalidOperationException(\"Stride.Core build has no accessible PreloadLibrary — resolver/runtime mismatch or trimming removed it.\");","typeGuard":"static bool HasPreloadLibrary(Assembly strideCore) =>\n    strideCore.GetType(\"Stride.Core.NativeLibraryHelper\")\n        ?.GetMethod(\"PreloadLibrary\") != null;","tryCatchPattern":"try\n{\n    resolver.SetupNuGet(packageName, packageVersion, targetFramework);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Couldn't find method 'PreloadLibrary'\"))\n{\n    logger.Error(\"PreloadLibrary missing on Stride.Core.NativeLibraryHelper; check version alignment and trimming settings.\");\n    throw;\n}","preventionTips":["Exclude Stride.Core from publish trimming (TrimMode=partial or TrimmerRootAssembly).","Pin Stride runtime versions to those the resolver's reflection contract targets.","Run SetupNuGet as part of CI so API drift is caught before release."],"tags":["reflection","method-not-found","version-mismatch"],"backgroundTag":"class-not-found","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}