stride3d/stride · error · InvalidOperationException

Error while pre-loading package

Error message

Error while pre-loading package [{filePath}]

What it means

Package.LoadRaw wraps the whole package pre-loading (parsing, migration, asset loading) in a try/catch and rethrows any exception as an InvalidOperationException with this message, preserving the original as InnerException.

Solutions

  1. Inspect the InnerException to find the root cause
  2. Re-save the package with a compatible Stride version
  3. Fix or remove the corrupt asset/dependency reported by the inner exception

Example fix

// before
var package = Package.LoadRaw(log, path);
// after
try { var package = Package.LoadRaw(log, path); }
catch (InvalidOperationException ex) when (ex.InnerException != null)
{ log.Error($"Package load failed: {ex.InnerException.Message}"); throw; }
Defensive patterns

Strategy: try-catch

Try / catch

try { pkg = Package.LoadRaw(log, path); } catch (InvalidOperationException ex) { log.Error($"Pre-load failed: {ex.InnerException?.Message ?? ex.Message}"); }

Prevention

When it happens

Trigger: Any failure inside LoadRaw's load pipeline — malformed package YAML, migration errors, IO failures while reading the package or its assets, plugin load failures.

Common situations: Package saved with a newer Stride version; corrupted asset content; broken session/package references; missing dependent plugin assemblies.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/Package.cs:626

                ? AssetFileSerializer.Load<Package>(new MemoryStream(packageFile.AssetContent), filePath, log)
                : AssetFileSerializer.Load<Package>(filePath, log);
            var package = loadResult.Asset;
            package.FullPath = packageFile.FilePath;
            // .sdpkg has no serialized name (identity = file name). PackageSession derives this on
            // session load; do it here too so a direct Package.Load doesn't leave Meta.Name null.
            if (string.IsNullOrWhiteSpace(package.Meta.Name) && package.FullPath is not null)
                package.Meta.Name = package.FullPath.GetFileNameWithoutExtension();
            // A package always carries a version. The session graph-walk overwrites this with the
            // authored csproj PackageVersion when available; this guarantees the value is never null.
            package.Meta.Version ??= GetFallbackVersion(Path.GetDirectoryName(filePath));
            package.PreviousPackagePath = packageFile.OriginalFilePath;
            package.IsDirty = packageFile.AssetContent is not null || loadResult.AliasOccurred;

            return package;
        }
        catch (Exception ex)
        {
            throw new InvalidOperationException($"Error while pre-loading package [{filePath}]", ex);
        }
    }

    // Fallback version for a package with none authored: a dev-source package's PackageVersion is
    // computed in a build target (empty at static eval), so use StrideVersion for packages inside
    // this Stride checkout; anything else gets a neutral default.
    internal static PackageVersion GetFallbackVersion(string? directory)
        => directory is not null && DirectoryHelper.FindRootDevDirectory(directory) is not null
            ? new PackageVersion(StrideVersion.NuGetVersion)
            : new PackageVersion("1.0.0");

    public static PackageContainer LoadProject(ILogger log, string filePath)
    {
        if (SupportedProgrammingLanguages.IsProjectExtensionSupported(Path.GetExtension(filePath).ToLowerInvariant()))
        {
            var projectPath = filePath;
            var packagePath = Path.ChangeExtension(filePath, Package.PackageFileExtension);
            var packageExists = File.Exists(packagePath);

View on GitHub (pinned to 96fad776d2)