stride3d/stride · error · InvalidOperationException
Couldn't find method 'PreloadLibrary' in
Error message
Couldn't find method 'PreloadLibrary' in {nativeLibraryHelperType} What it means
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.
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.
Example fix
// before publishOptions.TrimMode = "full"; // trims PreloadLibrary away from Stride.Core // after publishOptions.TrimMode = "partial"; // or exclude Stride.Core from trimming
Defensive patterns
Strategy: try-catch
Validate before calling
var t = Assembly.LoadFrom(strideCorePath).GetType("Stride.Core.NativeLibraryHelper");
if (t?.GetMethod("PreloadLibrary") == null)
throw new InvalidOperationException("Stride.Core build has no accessible PreloadLibrary — resolver/runtime mismatch or trimming removed it."); Type guard
static bool HasPreloadLibrary(Assembly strideCore) =>
strideCore.GetType("Stride.Core.NativeLibraryHelper")
?.GetMethod("PreloadLibrary") != null; Try / catch
try
{
resolver.SetupNuGet(packageName, packageVersion, targetFramework);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Couldn't find method 'PreloadLibrary'"))
{
logger.Error("PreloadLibrary missing on Stride.Core.NativeLibraryHelper; check version alignment and trimming settings.");
throw;
} Prevention
- 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.
When it happens
Trigger: nativeLibraryHelperType was found but has no 'PreloadLibrary' method with a bindable signature (renamed, internal, or parameter changes) in the restored Stride.Core version.
Common situations: Stride runtime upgraded ahead of the NuGetResolver reflection contract; custom Stride.Core forks without PreloadLibrary; strict trimming removing the method.
Related errors
- Couldn't find method 'RegisterDependency' in
- Couldn't find type 'Stride.Core.NativeLibraryHelper' in
- An error occurred while updating the value of the node, see…
- An unknown EffectParameterClass was found.
- An unknown EffectParameterType was found.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/384daf6f909f872a.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs:289
var nativeLibraryHelperType = strideCoreAssembly.GetType("Stride.Core.NativeLibraryHelper")
?? throw new InvalidOperationException($"Couldn't find type 'Stride.Core.NativeLibraryHelper' in {strideCoreAssembly}");
var registerDependencyMethod = nativeLibraryHelperType.GetMethod("RegisterDependency")
?? throw new InvalidOperationException($"Couldn't find method 'RegisterDependency' in {nativeLibraryHelperType}");
foreach (var lib in nativeLibs)
registerDependencyMethod.Invoke(null, [lib]);
}
/// <summary>
/// Loads the listed native libs in Stride.Core.NativeLibraryHelper using reflection to avoid a compile time dependency on Stride.Core
/// </summary>
private static void LoadNativeDependencies(Dictionary<string, string> assemblyNameToPath, List<string> nativeLibs)
{
var strideCoreAssembly = Assembly.LoadFrom(assemblyNameToPath["Stride.Core"])
?? throw new InvalidOperationException("Couldn't find assembly 'Stride.Core' in restored packages");
var nativeLibraryHelperType = strideCoreAssembly.GetType("Stride.Core.NativeLibraryHelper")
?? throw new InvalidOperationException($"Couldn't find type 'Stride.Core.NativeLibraryHelper' in {strideCoreAssembly}");
var preloadLibraryMethod = nativeLibraryHelperType.GetMethod("PreloadLibrary")
?? throw new InvalidOperationException($"Couldn't find method 'PreloadLibrary' in {nativeLibraryHelperType}");
foreach (var lib in nativeLibs)
{
var libName = Path.GetFileNameWithoutExtension(lib);
preloadLibraryMethod.Invoke(null, [libName, null]);
}
}
public class Logger : ILogger
{
private readonly object logLock = new();
private Action<LogLevel, string>? action;
public List<(LogLevel Level, string Message)> Logs { get; } = [];
public void SetupLogAction(Action<LogLevel, string> action)
{
lock (logLock)
{
this.action = action;View on GitHub (pinned to 96fad776d2)