{"record":{"id":"158a4728574fa3bd","repo":"stride3d/stride","slug":"filepath-must-be-relative","errorCode":null,"errorMessage":"filePath must be relative","messagePattern":"filePath must be relative","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/PackageLoadingAssetFile.cs","lineNumber":54,"sourceCode":"    /// <param name=\"sourceFolder\">The source folder.</param>\n    public PackageLoadingAssetFile(UFile filePath, UDirectory sourceFolder)\n    {\n        FilePath = filePath;\n        OriginalFilePath = FilePath;\n        SourceFolder = sourceFolder;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"PackageLoadingAssetFile\" /> class.\n    /// </summary>\n    /// <param name=\"package\">The package this asset will be part of.</param>\n    /// <param name=\"filePath\">The relative file path (from default asset folder).</param>\n    /// <param name=\"sourceFolder\">The source folder (optional, can be null).</param>\n    /// <exception cref=\"ArgumentException\">filePath must be relative</exception>\n    public PackageLoadingAssetFile(Package package, UFile filePath, UDirectory sourceFolder)\n    {\n        if (filePath.IsAbsolute)\n            throw new ArgumentException(\"filePath must be relative\", filePath);\n\n        SourceFolder = UPath.Combine(package.RootDirectory!, sourceFolder ?? package.GetDefaultAssetFolder());\n        FilePath = UPath.Combine(SourceFolder, filePath);\n        OriginalFilePath = FilePath;\n    }\n\n    public IReference ToReference()\n    {\n        return new AssetReference(AssetId.Empty, AssetLocation);\n    }\n\n    public YamlAsset? AsYamlAsset()\n    {\n        // The asset file might have been been marked as deleted during the run of asset upgrader. In this case let's just return null.\n        if (Deleted)\n            return null;\n\n        try","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/PackageLoadingAssetFile.cs#L36-L72","documentation":"PackageLoadingAssetFile's constructor requires a relative asset file path (relative to the package's default asset folder). The library throws ArgumentException when a UFile with an absolute path is passed, because it later combines it with SourceFolder and an absolute path would produce an invalid combined path.","triggerScenarios":"Calling new PackageLoadingAssetFile(package, filePath, sourceFolder) with a UFile whose IsAbsolute is true, e.g. 'C:/proj/assets/myasset.sdtex' instead of 'myasset.sdtex'.","commonSituations":"Paths built from File.OpenDialog results, Environment.CurrentDirectory concatenation, or full paths loaded from config/serialized data instead of package-relative paths.","solutions":["Convert the absolute path to a package-relative one before constructing (make it relative to the default asset folder / SourceFolder)","Use the UFile/UDirectory helpers to strip the folder prefix","Ensure the caller stores relative paths in config/serialization"],"exampleFix":"// before\nvar file = new UFile(@\"C:\\MyGame\\Assets\\box.sdtex\");\nvar item = new PackageLoadingAssetFile(package, file, null);\n// after\nvar file = new UFile(@\"C:\\MyGame\\Assets\\box.sdtex\");\nvar rel = new UFile(file.MakeRelative(new UDirectory(package.RootDirectory + \"/Assets\")));\nvar item = new PackageLoadingAssetFile(package, rel, null);","handlingStrategy":"validation","validationCode":"if (filePath == null || filePath.IsAbsolute)\n    throw new ArgumentException(\"Pass a path relative to the package's default asset folder\", nameof(filePath));","typeGuard":"bool IsRelativePath(UFile f) => f != null && !f.IsAbsolute;","tryCatchPattern":null,"preventionTips":["Store asset paths package-relative in configs and serialization","Convert dialog/open-file results to relative paths at the boundary","Write a unit test exercising the constructor with an absolute path"],"tags":["argument","path","assets"],"backgroundTag":"invalid-argument-value","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"}