stride3d/stride · error · InvalidOperationException
Could not load package
Error message
Could not load package {packageInfo.Name}:{Environment.NewLine}{logger.ToText()} What it means
The same Load method as above does find the package file but Package.Load logs errors into a LoggerResult; if logger.HasErrors the package exists yet failed to load, and the full logger text is embedded in the InvalidOperationException. This surfaces deserialization, dependency, or assembly-reference problems with the template package.
Solutions
- Read the embedded logger output to see the specific load error (missing dependency, deserialize failure, etc.).
- Delete the cached package from the NuGet global-packages folder and let it re-download.
- Restore a consistent set of Stride package versions (clear all stride.* of mismatched versions and restore).
- Reinstall/repair Stride if the corruption persists.
Example fix
// clear corrupt cache entry and restore rm -rf ~/.nuget/packages/stride.assets.presentation dotnet restore MyGame.csproj
Defensive patterns
Strategy: try-catch
Validate before calling
var cachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".nuget", "packages", "stride.assets.presentation", StrideVersion.NuGetVersion);
if (!Directory.Exists(cachePath) || !Directory.EnumerateFileSystemEntries(cachePath).Any())
throw new InvalidOperationException("Cached package missing or empty — restore it."); Try / catch
try
{
StrideDefaultTemplates.Load(session, logger);
}
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Could not load package"))
{
logger.Error($"Package load failed; clear the NuGet cache entry and restore: {ex.Message}");
} Prevention
- Let downloads complete; avoid killing restores mid-flight to prevent cache corruption
- Use one consistent package source for all stride.* packages
- Re-restore after Stride upgrades so versions stay consistent
When it happens
Trigger: Package.Load on Stride.Assets.Presentation or Stride.SpriteStudio.Offline logs errors — corrupt package cache entry, incompatible package version, missing dependency assemblies, or broken package metadata.
Common situations: Interrupted download leaving a partial/corrupt package in the NuGet cache; package version restored from a different feed with mismatched dependencies; disk/permission problems while reading the cache.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- Could not find package
- Asset returned by CreateAssets has no location. Use…
- Could not find installation path for package
- Could not locate native library
- Could not restore (needed to regenerate shader code). Check…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/28914f9808725b30.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Assets/Templates/StrideDefaultTemplates.cs:39
/// Loads default templates. Pass <paramref name="loadAssemblyReferences"/>=false in headless
/// test runners so the .sdpkg's referenced assemblies (Stride.Particles etc.) don't get loaded
/// from .nuget cache — a later sample regen loads them from the sample's bin/ via a different
/// path, producing duplicate Assembly objects and a DataContract alias conflict at runtime.
/// </summary>
public static void Load(bool loadAssemblyReferences = true)
{
// Only TemplateFolders are needed here (loaded regardless of this flag); skip the package's
// assets — they're unused for template registration and slow to load.
var loadParams = new PackageLoadParameters { LoadAssemblyReferences = loadAssemblyReferences, AutoLoadTemporaryAssets = false };
foreach (var packageInfo in new[] { new { Name = "Stride.Assets.Presentation", Version = StrideVersion.NuGetVersion }, new { Name = "Stride.SpriteStudio.Offline", Version = StrideVersion.NuGetVersion } })
{
var logger = new LoggerResult();
var packageFile = PackageStore.Instance.GetPackageFileName(packageInfo.Name, new PackageVersionRange(new PackageVersion(packageInfo.Version)));
if (packageFile is null)
throw new InvalidOperationException($"Could not find package {packageInfo.Name} {packageInfo.Version}. Ensure packages have been resolved.");
var package = Package.Load(logger, packageFile.ToOSPath(), loadParams);
if (logger.HasErrors)
throw new InvalidOperationException($"Could not load package {packageInfo.Name}:{Environment.NewLine}{logger.ToText()}");
TemplateManager.RegisterPackage(package);
}
DotNetNewTemplateBridge.RegisterProjectTemplates();
}
}
View on GitHub (pinned to 96fad776d2)