dotnet/maui · error · ArgumentException
uri
Error message
uri
What it means
Thrown by Platform.ResolveMsAppDataUri when the URI's scheme is not ms-appdata. The method is specifically for resolving ms-appdata URIs; any other scheme (http, file, content, etc.) is rejected by the outer else branch. The error message is terse ('uri') because the method assumes callers pre-filter by scheme.
Source
Thrown at src/Compatibility/Core/src/Android/AppCompat/Platform.cs:871
if (uri.LocalPath.StartsWith("/local"))
{
filePath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), uri.LocalPath.Substring(7));
}
else if (uri.LocalPath.StartsWith("/temp"))
{
filePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), uri.LocalPath.Substring(6));
}
else
{
throw new ArgumentException("Invalid Uri", "Source");
}
return filePath;
}
else
{
throw new ArgumentException("uri");
}
}
}
}
View on GitHub (pinned to f377ff1c5e)
Solutions
- Only call ResolveMsAppDataUri after confirming uri.Scheme == "ms-appdata".
- Route non-ms-appdata URIs to the appropriate resolver (e.g., file:// to a file path resolver, http:// to a network image loader).
- Wrap the call in a scheme-based switch to dispatch to the correct handler.
Example fix
// before
var uri = new Uri("file:///data/app/photo.png");
var path = Platform.ResolveMsAppDataUri(uri); // throws
// after
string path;
if (uri.Scheme == "ms-appdata")
path = Platform.ResolveMsAppDataUri(uri);
else if (uri.IsFile)
path = uri.LocalPath;
else
throw new NotSupportedException($"Unsupported scheme: {uri.Scheme}"); Defensive patterns
Strategy: validation
Validate before calling
if (uri.Scheme != "ms-appdata")
throw new ArgumentException($"Expected ms-appdata scheme, got {uri.Scheme}.", nameof(uri));
var path = Platform.ResolveMsAppDataUri(uri); Type guard
static bool IsMsAppDataUri(Uri uri) => uri?.Scheme == "ms-appdata";
Prevention
- Dispatch URIs by scheme before calling ResolveMsAppDataUri.
- Create a URI resolver facade that hides platform-specific resolvers from callers.
- Add a scheme-check unit test for the image/file source helper.
When it happens
Trigger: Passing an http(s), file://, content://, or plain relative URI to ResolveMsAppDataUri. The outer if checks uri.Scheme == "ms-appdata" and the else branch throws unconditionally.
Common situations: Generic image/file loading code that routes all URIs through ResolveMsAppDataUri without checking the scheme. Cross-platform code that uses file:// on Android but ms-appdata on UWP, calling the same resolver.
Related errors
- Invalid Uri
- InsertPageBefore is not supported globally on Android, pleas
- PopAsync is not supported globally on Android, please use a
- PopToRootAsync is not supported globally on Android, please
- PushAsync is not supported globally on Android, please use a
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/e582dcf2b06c6c88.
Report an issue: GitHub.