{"record":{"id":"4172b5a770d6f90f","repo":"dotnet/maui","slug":"invalid-uri","errorCode":null,"errorMessage":"Invalid Uri","messagePattern":"Invalid Uri","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Android/AppCompat/Platform.cs","lineNumber":864,"sourceCode":"\t\t}\n\n\t\tinternal static string ResolveMsAppDataUri(Uri uri)\n\t\t{\n\t\t\tif (uri.Scheme == \"ms-appdata\")\n\t\t\t{\n\t\t\t\tstring filePath = string.Empty;\n\n\t\t\t\tif (uri.LocalPath.StartsWith(\"/local\"))\n\t\t\t\t{\n\t\t\t\t\tfilePath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), uri.LocalPath.Substring(7));\n\t\t\t\t}\n\t\t\t\telse if (uri.LocalPath.StartsWith(\"/temp\"))\n\t\t\t\t{\n\t\t\t\t\tfilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), uri.LocalPath.Substring(6));\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tthrow new ArgumentException(\"Invalid Uri\", \"Source\");\n\t\t\t\t}\n\n\t\t\t\treturn filePath;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthrow new ArgumentException(\"uri\");\n\t\t\t}\n\n\t\t}\n\t}\n}\n","sourceCodeStart":846,"sourceCodeEnd":877,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Android/AppCompat/Platform.cs#L846-L877","documentation":"Thrown by Platform.ResolveMsAppDataUri when the URI uses the ms-appdata scheme but its LocalPath does not start with /local or /temp. The resolver only supports two ms-appdata sub-paths: /local (mapped to the app's MyDocuments) and /temp (mapped to the system temp directory). Any other path (e.g., /roaming, /cache) is rejected.","triggerScenarios":"Supplying an ms-appdata URI with an unsupported path segment such as ms-appdata:///roaming/file.json or ms-appdata:///cache/data.db. The resolver parses the scheme correctly but the LocalPath branch falls through to the else clause.","commonSituations":"Porting a UWP app that used ms-appdata:///local and adding a roaming path that Android does not support. Constructing ms-appdata URIs dynamically with a path variable that can take unsupported values. Misremembering the supported sub-paths.","solutions":["Use only ms-appdata:///local/... or ms-appdata:///temp/... paths on Android.","For roaming-equivalent data, use a file in the local path and sync via a custom mechanism, or use a non-ms-appdata file URI.","Validate the URI path before passing it to the image/file source; surface a friendly error if the path is unsupported."],"exampleFix":"// before\nvar uri = new Uri(\"ms-appdata:///roaming/settings.json\");\nvar path = Platform.ResolveMsAppDataUri(uri); // throws\n\n// after\nvar uri = new Uri(\"ms-appdata:///local/settings.json\");\nvar path = Platform.ResolveMsAppDataUri(uri);","handlingStrategy":"validation","validationCode":"// Validate the ms-appdata path is supported before resolving.\nstatic bool IsValidMsAppDataPath(Uri uri)\n{\n    return uri.Scheme == \"ms-appdata\"\n        && (uri.LocalPath.StartsWith(\"/local\") || uri.LocalPath.StartsWith(\"/temp\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict ms-appdata URIs to /local and /temp on Android.","For roaming data, use the local folder plus a sync mechanism rather than ms-appdata:///roaming.","Validate URIs in a helper method and surface a friendly error for unsupported paths."],"tags":["android","uri","ms-appdata","file-path","platform"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}