dotnet/maui · error · ArgumentNullException

uri

Error message

uri

What it means

DeregisterLink(Uri) is the URI-based overload for removing a Spotlight-indexed deep link. It throws ArgumentNullException when the passed Uri is null or its string representation is empty/whitespace, because the URI string is used directly as the CoreSpotlight item identifier for deletion.

Source

Thrown at src/Compatibility/Core/src/iOS/iOSAppLinks.cs:22

using Foundation;
using ObjCRuntime;
using UIKit;

namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
	internal class IOSAppLinks : IAppLinks
	{
		public async void DeregisterLink(IAppLinkEntry appLink)
		{
			if (string.IsNullOrWhiteSpace(appLink.AppLinkUri?.ToString()))
				throw new ArgumentNullException("AppLinkUri");
			await RemoveLinkAsync(appLink.AppLinkUri?.ToString());
		}

		public async void DeregisterLink(Uri uri)
		{
			if (string.IsNullOrWhiteSpace(uri?.ToString()))
				throw new ArgumentNullException(nameof(uri));
			await RemoveLinkAsync(uri.ToString());
		}

		public async void RegisterLink(IAppLinkEntry appLink)
		{
			if (string.IsNullOrWhiteSpace(appLink.AppLinkUri?.ToString()))
				throw new ArgumentNullException("AppLinkUri");
			await AddLinkAsync(appLink);
		}

		public async void DeregisterAll()
		{
			await ClearIndexedDataAsync();
		}

		static async Task AddLinkAsync(IAppLinkEntry deepLinkUri)
		{
			var appDomain = NSBundle.MainBundle.BundleIdentifier;

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Validate the Uri is non-null and well-formed before calling DeregisterLink.
  2. Guard at the call site: `if (uri != null && !string.IsNullOrWhiteSpace(uri.ToString())) Application.Current.AppLinks.DeregisterLink(uri);`
  3. Prefer the IAppLinkEntry overload when working with full AppLinkEntry objects that carry their own AppLinkUri.

Example fix

// before
Application.Current.AppLinks.DeregisterLink(storedUri); // storedUri may be null

// after
if (storedUri is not null && Uri.IsWellFormedUriString(storedUri.ToString(), UriKind.Absolute))
    Application.Current.AppLinks.DeregisterLink(storedUri);
Defensive patterns

Strategy: validation

Validate before calling

if (uri is null || string.IsNullOrWhiteSpace(uri.ToString()))
    return;
Application.Current.AppLinks.DeregisterLink(uri);

Prevention

When it happens

Trigger: Calling `Application.Current.AppLinks.DeregisterLink(uri)` where `uri` is null or `uri.ToString()` returns an empty or whitespace string. Passing a default(Uri) or a Uri constructed from an empty string.

Common situations: Storing URIs in collections where some entries were never populated. Passing a Uri variable that was conditionally assigned. Deserialization producing null Uri fields.

Related errors


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