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

  1. Only call ResolveMsAppDataUri after confirming uri.Scheme == "ms-appdata".
  2. Route non-ms-appdata URIs to the appropriate resolver (e.g., file:// to a file path resolver, http:// to a network image loader).
  3. 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

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


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/e582dcf2b06c6c88. Report an issue: GitHub.