{"record":{"id":"5f6eac64e24e4760","repo":"stride3d/stride","slug":"couldn-t-find-type-stride-core-nativelibraryhelper-in","errorCode":null,"errorMessage":"Couldn't find type 'Stride.Core.NativeLibraryHelper' in {strideCoreAssembly}","messagePattern":"Couldn't find type 'Stride\\.Core\\.NativeLibraryHelper' in (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs","lineNumber":272,"sourceCode":"                }\n            }\n        }\n    }\n\n    private static void CheckPackageSource(ISettings settings, string name, string url)\n    {\n        settings.AddOrUpdate(\"packageSources\", new SourceItem(name, url));\n    }\n\n    /// <summary>\n    /// Registers 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 RegisterNativeDependencies(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 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)","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs#L254-L290","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Align the Stride.NuGetResolver version with the Stride runtime package version being restored.","Verify with a quick reflection dump that Stride.Core.dll contains type Stride.Core.NativeLibraryHelper.","Restore a matching, published Stride package version (not a mismatched or custom build).","Clear NuGet cache and re-restore to rule out a stale/corrupted Stride.Core.dll."],"exampleFix":"// before: mismatched package set\nSetupNuGet(\"Stride.Core\", \"4.0.9\", ...); // 4.0 Stride.Core lacks the expected helper type layout\n// after\nSetupNuGet(\"Stride.Core\", \"4.2.1\", ...); // matches resolver's reflected API","handlingStrategy":"try-catch","validationCode":"var asm = Assembly.LoadFrom(strideCorePath);\nif (asm.GetType(\"Stride.Core.NativeLibraryHelper\") == null)\n    throw new InvalidOperationException($\"{strideCorePath} does not contain Stride.Core.NativeLibraryHelper — version mismatch with NuGetResolver.\");","typeGuard":"static bool HasNativeLibraryHelper(Assembly strideCore) =>\n    strideCore.GetType(\"Stride.Core.NativeLibraryHelper\") != null;","tryCatchPattern":"try\n{\n    resolver.SetupNuGet(packageName, packageVersion, targetFramework);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Couldn't find type 'Stride.Core.NativeLibraryHelper'\"))\n{\n    logger.Error($\"Restored Stride.Core version does not match the resolver's reflected API: {ex.Message}\");\n    throw;\n}","preventionTips":["Use the same Stride version for runtime packages and the NuGetResolver tool.","Test SetupNuGet in CI against every Stride version you support.","Note that reflection contracts break silently on Stride upgrades — read the changelog."],"tags":["reflection","type-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"}