{"record":{"id":"15e61e2698f5d327","repo":"dotnet/maui","slug":"invalid-uri-15e61e","errorCode":null,"errorMessage":"Invalid Uri","messagePattern":"Invalid Uri","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/Platform.cs","lineNumber":656,"sourceCode":"\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\tvar libraryPath = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User)[0].Path;\n\t\t\t\t\tfilePath = IOPath.Combine(libraryPath, 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 = IOPath.Combine(IOPath.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\t\t}\n\n\t\tinternal void SubscribeToAlertsAndActionSheets()\n\t\t{\n\t\t\tvar busyCount = 0;\n\t\t\tMessagingCenter.Subscribe(this, Page.BusySetSignalName, (Page sender, bool enabled) =>\n\t\t\t{\n\t\t\t\tif (!PageIsChildOfPlatform(sender))\n\t\t\t\t\treturn;\n\t\t\t\tbusyCount = Math.Max(0, enabled ? busyCount + 1 : busyCount - 1);","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/Platform.cs#L638-L674","documentation":"Platform.cs throws ArgumentException(\"Invalid Uri\", \"Source\") when a file-style Uri (file:// or app local) does not start with /local or /temp. The platform only resolves two well-known iOS app sandbox prefixes for local file paths; anything else is rejected as invalid source.","triggerScenarios":"Passing a Uri to the platform whose LocalPath does not begin with /local or /temp; e.g. an absolute filesystem path encoded as a Uri with a different prefix, or a malformed app-resource Uri.","commonSituations":"Loading images/files via UriSource with paths outside the recognized sandbox; copying files to Documents but referencing with /documents prefix; bundling resource Uris that don't match the local/temp convention; cross-platform code passing platform-specific paths.","solutions":["Use /local (Library) or /temp (Tmp) prefixed paths for file Uris on iOS.","Prefer FileImageSource or bundle resources rather than raw file Uris.","If you must reference Documents, copy the file into Library or Tmp first."],"exampleFix":"// before\nnew UriImageSource { Uri = new Uri(\"file:///documents/img.png\") };\n// after\n// copy file into LibraryDirectory, then:\nnew UriImageSource { Uri = new Uri(\"file:///local/img.png\") };","handlingStrategy":"validation","validationCode":"// Validate the local-path prefix before resolving.\nif (!uri.LocalPath.StartsWith(\"/local\") && !uri.LocalPath.StartsWith(\"/temp\"))\n    throw new ArgumentException(\"Uri must reference /local (Library) or /temp on iOS.\");","typeGuard":"static bool IsRecognizedLocalUri(Uri u) =>\n    u != null && u.IsAbsoluteUri &&\n    (u.LocalPath.StartsWith(\"/local\") || u.LocalPath.StartsWith(\"/temp\"));","tryCatchPattern":null,"preventionTips":["Use /local or /temp prefixes for file Uris on iOS.","Prefer FileImageSource or bundled resources over raw file Uris.","Copy Documents files into Library or Tmp before referencing."],"tags":["maui","xamarin-forms","ios","uri","files","image-source","argument"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}