dotnet/maui · critical · ArgumentNullException

application

Error message

application

What it means

FormsApplicationDelegate.LoadApplication throws ArgumentNullException("application") when given a null Application. The platform cannot bootstrap without an Application instance; rejecting null here fails fast rather than dereferencing it later in property/event wiring.

Source

Thrown at src/Compatibility/Core/src/iOS/FormsApplicationDelegate.cs:135

			// applicationWillTerminate
			//application.SendTerminate ();
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && _application != null)
			{
				_application.PropertyChanged -= ApplicationOnPropertyChanged;
				_application.PropertyChanging -= ApplicationOnPropertyChanging;
			}

			base.Dispose(disposing);
		}

		protected void LoadApplication(Application application)
		{
			if (application == null)
				throw new ArgumentNullException("application");

			Application.SetCurrentApplication(application);
			_application = application;
			(application as IApplicationController)?.SetAppIndexingProvider(new IOSAppIndexingProvider());

			application.PropertyChanged += ApplicationOnPropertyChanged;
			application.PropertyChanging += ApplicationOnPropertyChanging;
		}

		void ApplicationOnPropertyChanging(object sender, PropertyChangingEventArgs args)
		{
			if (args.PropertyName == nameof(_application.MainPage))
				UpdatingMainPage();
		}

		void ApplicationOnPropertyChanged(object sender, PropertyChangedEventArgs args)
		{
			if (args.PropertyName == "MainPage")

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Construct a valid Application instance before passing it to LoadApplication.
  2. Audit DI registration for the Application type.
  3. Add a null check at the call site to surface configuration errors earlier with a clearer message.

Example fix

// before
LoadApplication(_container.GetInstance<Application>());
// after
var app = _container.GetInstance<Application>()
    ?? throw new InvalidOperationException("DI failed to resolve Application.");
LoadApplication(app);
Defensive patterns

Strategy: validation

Validate before calling

if (application == null)
    throw new InvalidOperationException("Application instance is null; check DI/constructor.");
LoadApplication(application);

Type guard

static bool IsValidApplication(Application a) => a != null;

Prevention

When it happens

Trigger: Calling LoadApplication(null); typically passing a DI-resolved Application that failed to construct, or a constructor expression returning null.

Common situations: DI container misconfiguration returning null Application; conditional construction like `LoadApplication(useMock ? null : new App())`; app-builder logic that has not built the Application yet.

Related errors


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