stride3d/stride · error · InvalidOperationException

Couldn't find type 'Stride.Core.NativeLibraryHelper' in

Error message

Couldn't find type 'Stride.Core.NativeLibraryHelper' in {strideCoreAssembly}

What it means

After loading the Stride.Core assembly, RegisterNativeDependencies reflects for the type Stride.Core.NativeLibraryHelper to register native library dependencies. If GetType returns null the resolver throws, meaning the loaded Stride.Core.dll does not expose that type — usually a version or assembly mismatch, since the resolver avoids a compile-time dependency on Stride.Core.

Solutions

  1. Align the Stride.NuGetResolver version with the Stride runtime package version being restored.
  2. Verify with a quick reflection dump that Stride.Core.dll contains type Stride.Core.NativeLibraryHelper.
  3. Restore a matching, published Stride package version (not a mismatched or custom build).
  4. Clear NuGet cache and re-restore to rule out a stale/corrupted Stride.Core.dll.

Example fix

// before: mismatched package set
SetupNuGet("Stride.Core", "4.0.9", ...); // 4.0 Stride.Core lacks the expected helper type layout
// after
SetupNuGet("Stride.Core", "4.2.1", ...); // matches resolver's reflected API
Defensive patterns

Strategy: try-catch

Validate before calling

var asm = Assembly.LoadFrom(strideCorePath);
if (asm.GetType("Stride.Core.NativeLibraryHelper") == null)
    throw new InvalidOperationException($"{strideCorePath} does not contain Stride.Core.NativeLibraryHelper — version mismatch with NuGetResolver.");

Type guard

static bool HasNativeLibraryHelper(Assembly strideCore) =>
    strideCore.GetType("Stride.Core.NativeLibraryHelper") != null;

Try / catch

try
{
    resolver.SetupNuGet(packageName, packageVersion, targetFramework);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Couldn't find type 'Stride.Core.NativeLibraryHelper'"))
{
    logger.Error($"Restored Stride.Core version does not match the resolver's reflected API: {ex.Message}");
    throw;
}

Prevention

When it happens

Trigger: Assembly.LoadFrom returned a Stride.Core assembly built without/moving NativeLibraryHelper (internal namespace change across Stride versions), or the wrong DLL got loaded from the path map.

Common situations: Mixing Stride package versions (e.g. resolver expecting 4.x API but 3.x Stride.Core restored); NuGetResolver version out of sync with the runtime packages; trimmed/AOT assemblies missing internal types.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/5f6eac64e24e4760. Report an issue: GitHub.

Appendix: source

Thrown at sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs:272

                }
            }
        }
    }

    private static void CheckPackageSource(ISettings settings, string name, string url)
    {
        settings.AddOrUpdate("packageSources", new SourceItem(name, url));
    }

    /// <summary>
    /// Registers the listed native libs in Stride.Core.NativeLibraryHelper using reflection to avoid a compile time dependency on Stride.Core
    /// </summary>
    private static void RegisterNativeDependencies(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 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)

View on GitHub (pinned to 96fad776d2)