{"record":{"id":"f5cf38dcb853cb67","repo":"stride3d/stride","slug":"error-while-pre-loading-package-filepath","errorCode":null,"errorMessage":"Error while pre-loading package [{filePath}]","messagePattern":"Error while pre-loading package \\[(.+?)\\]","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Package.cs","lineNumber":626,"sourceCode":"                ? AssetFileSerializer.Load<Package>(new MemoryStream(packageFile.AssetContent), filePath, log)\n                : AssetFileSerializer.Load<Package>(filePath, log);\n            var package = loadResult.Asset;\n            package.FullPath = packageFile.FilePath;\n            // .sdpkg has no serialized name (identity = file name). PackageSession derives this on\n            // session load; do it here too so a direct Package.Load doesn't leave Meta.Name null.\n            if (string.IsNullOrWhiteSpace(package.Meta.Name) && package.FullPath is not null)\n                package.Meta.Name = package.FullPath.GetFileNameWithoutExtension();\n            // A package always carries a version. The session graph-walk overwrites this with the\n            // authored csproj PackageVersion when available; this guarantees the value is never null.\n            package.Meta.Version ??= GetFallbackVersion(Path.GetDirectoryName(filePath));\n            package.PreviousPackagePath = packageFile.OriginalFilePath;\n            package.IsDirty = packageFile.AssetContent is not null || loadResult.AliasOccurred;\n\n            return package;\n        }\n        catch (Exception ex)\n        {\n            throw new InvalidOperationException($\"Error while pre-loading package [{filePath}]\", ex);\n        }\n    }\n\n    // Fallback version for a package with none authored: a dev-source package's PackageVersion is\n    // computed in a build target (empty at static eval), so use StrideVersion for packages inside\n    // this Stride checkout; anything else gets a neutral default.\n    internal static PackageVersion GetFallbackVersion(string? directory)\n        => directory is not null && DirectoryHelper.FindRootDevDirectory(directory) is not null\n            ? new PackageVersion(StrideVersion.NuGetVersion)\n            : new PackageVersion(\"1.0.0\");\n\n    public static PackageContainer LoadProject(ILogger log, string filePath)\n    {\n        if (SupportedProgrammingLanguages.IsProjectExtensionSupported(Path.GetExtension(filePath).ToLowerInvariant()))\n        {\n            var projectPath = filePath;\n            var packagePath = Path.ChangeExtension(filePath, Package.PackageFileExtension);\n            var packageExists = File.Exists(packagePath);","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Package.cs#L608-L644","documentation":"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.","triggerScenarios":"Any failure inside LoadRaw's load pipeline — malformed package YAML, migration errors, IO failures while reading the package or its assets, plugin load failures.","commonSituations":"Package saved with a newer Stride version; corrupted asset content; broken session/package references; missing dependent plugin assemblies.","solutions":["Inspect the InnerException to find the root cause","Re-save the package with a compatible Stride version","Fix or remove the corrupt asset/dependency reported by the inner exception"],"exampleFix":"// before\nvar package = Package.LoadRaw(log, path);\n// after\ntry { var package = Package.LoadRaw(log, path); }\ncatch (InvalidOperationException ex) when (ex.InnerException != null)\n{ log.Error($\"Package load failed: {ex.InnerException.Message}\"); throw; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { pkg = Package.LoadRaw(log, path); } catch (InvalidOperationException ex) { log.Error($\"Pre-load failed: {ex.InnerException?.Message ?? ex.Message}\"); }","preventionTips":["Always inspect InnerException for the root cause","Load packages with matching Stride versions","Log with a migration/logger result to capture per-asset errors"],"tags":["package","loading","wrapped-exception"],"backgroundTag":"file-read-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}