{"record":{"id":"cc83f8006b3a30d5","repo":"AvaloniaUI/Avalonia","slug":"folder-path-is-expected-to-be-an-absolute-link-wit","errorCode":null,"errorMessage":"Folder path is expected to be an absolute link with \"file\" or \"content\" scheme.","messagePattern":"Folder path is expected to be an absolute link with \"file\" or \"content\" scheme\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Android/Avalonia.Android/Platform/Storage/AndroidStorageProvider.cs","lineNumber":83,"sourceCode":"        var javaFile = new JavaFile(androidUriPath);\n        if (javaFile.Exists() && javaFile.IsFile)\n        {\n            return new BclStorageFile(new System.IO.FileInfo(javaFile.AbsolutePath));\n        }\n\n        return null;\n    }\n\n    public async Task<IStorageFolder?> TryGetFolderFromPathAsync(Uri folderPath)\n    {\n        if (folderPath is null)\n        {\n            throw new ArgumentNullException(nameof(folderPath));\n        }\n\n        if (folderPath is not { IsAbsoluteUri: true, Scheme: \"file\" or \"content\" })\n        {\n            throw new ArgumentException(\"Folder path is expected to be an absolute link with \\\"file\\\" or \\\"content\\\" scheme.\");\n        }\n\n        var androidUri = AndroidUri.Parse(folderPath.ToString());\n        if (androidUri?.Path is not {} androidUriPath)\n        {\n            return null;\n        }\n\n        var javaFile = new JavaFile(androidUriPath);\n        if (javaFile.Exists() && javaFile.IsDirectory)\n        {\n            return new BclStorageFolder(new System.IO.DirectoryInfo(javaFile.AbsolutePath));\n        }\n\n        return null;\n    }\n\n    public Task<IStorageFolder?> TryGetWellKnownFolderAsync(WellKnownFolder wellKnownFolder)","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Android/Avalonia.Android/Platform/Storage/AndroidStorageProvider.cs#L65-L101","documentation":"Thrown by AndroidStorageProvider.TryGetFolderFromPathAsync when the supplied Uri is not absolute or its Scheme is neither \"file\" nor \"content\". Same scheme requirement as the file variant: Android folders must be addressed via file:// or content://.","triggerScenarios":"Calling TryGetFolderFromPathAsync with a relative Uri or an absolute Uri whose scheme is not file/content (e.g. http, custom scheme, or a malformed path).","commonSituations":"Passing a directory path string instead of a properly-formed file:// URI; cross-platform code sharing a Uri of a different scheme; UriKind defaulting to relative for certain escaped inputs; receiving folder paths from desktop/iOS into Android.","solutions":["Build an absolute file:// or content:// URI before calling: new Uri(folderPath, UriKind.Absolute).","For filesystem paths, wrap as file:// via Path.GetFullPath + Uri construction.","Validate Uri.IsAbsoluteUri && Uri.Scheme in {\"file\",\"content\"} upstream and convert or reject.","Forward content:// folder URIs (e.g. from tree pickers) verbatim."],"exampleFix":"// before\nvar folder = await provider.TryGetFolderFromPathAsync(new Uri(\"/sdcard/Pictures\"));\n\n// after\nvar abs = System.IO.Path.GetFullPath(\"/sdcard/Pictures\");\nvar folder = await provider.TryGetFolderFromPathAsync(new Uri($\"file://{abs}\"));","handlingStrategy":"validation","validationCode":"// validate scheme before calling the provider\nif (folderPath is not { IsAbsoluteUri: true } || (folderPath.Scheme != \"file\" && folderPath.Scheme != \"content\"))\n    throw new ArgumentException(\"Use an absolute file:// or content:// URI.\");\nvar folder = await provider.TryGetFolderFromPathAsync(folderPath);","typeGuard":"static bool IsValidAndroidStorageUri(Uri? u) => u is { IsAbsoluteUri: true } && (u.Scheme == \"file\" || u.Scheme == \"content\");","tryCatchPattern":null,"preventionTips":["Always build absolute file:// or content:// URIs for folders.","Wrap directory paths with file://.","Validate IsAbsoluteUri and Scheme upstream.","Forward content:// tree URIs from pickers verbatim."],"tags":["android","storage","uri","validation","scheme"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}