dotnet/maui · error · NotImplementedException

The current platform does not implement the IFontNamedSizeSe

Error message

The current platform does not implement the IFontNamedSizeService dependency service.

What it means

Device.GetNamedSize (obsolete) resolves the platform IFontNamedSizeService via DependencyService and throws NotImplementedException when no platform registers that service. The null-coalescing operator turns a missing service into the exception. This path is legacy; the platform layer is expected to provide the service.

Source

Thrown at src/Controls/src/Core/Device.cs:179

		public static void StartTimer(TimeSpan interval, Func<bool> callback)
		{
			_ = callback ?? throw new ArgumentNullException(nameof(callback));

			var dispatcher = Application.Current.FindDispatcher();

			dispatcher.StartTimer(interval, callback);
		}

		/// <summary>Returns the named font size for the specified element type.</summary>
		/// <param name="size">The named size to retrieve.</param>
		/// <param name="targetElementType">The element type to get the named size for.</param>
		/// <param name="useOldSizes">Whether to use legacy font sizes.</param>
		/// <returns>The font size value.</returns>
		[Obsolete]
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes) =>
			DependencyService.Get<IFontNamedSizeService>()?.GetNamedSize(size, targetElementType, useOldSizes) ??
			throw new NotImplementedException("The current platform does not implement the IFontNamedSizeService dependency service.");

		[Obsolete]
		public static class Styles
		{
			public static readonly string TitleStyleKey = "TitleStyle";

			public static readonly string SubtitleStyleKey = "SubtitleStyle";

			public static readonly string BodyStyleKey = "BodyStyle";

			public static readonly string ListItemTextStyleKey = "ListItemTextStyle";

			public static readonly string ListItemDetailTextStyleKey = "ListItemDetailTextStyle";

			public static readonly string CaptionStyleKey = "CaptionStyle";

			public static readonly Style TitleStyle = new Style(typeof(Label)) { BaseResourceKey = TitleStyleKey };

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Migrate off the obsolete Device.GetNamedSize to the non-obsolete overload or use explicit numeric font sizes.
  2. On a custom platform, register an IFontNamedSizeService implementation via DependencyService.Register.
  3. In test code, register a stub IFontNamedSizeService before invoking GetNamedSize.

Example fix

// before
var size = Device.GetNamedSize(NamedSize.Medium, typeof(Label), useOldSizes: false);

// after
var size = Device.GetNamedSize(NamedSize.Medium, typeof(Label)); // non-obsolete overload
// or
label.FontSize = 14;
Defensive patterns

Strategy: validation

Validate before calling

// Check the service before calling the obsolete API.
var svc = DependencyService.Get<IFontNamedSizeService>();
if (svc is null)
    throw new InvalidOperationException("IFontNamedSizeService not registered on this platform.");

Prevention

When it happens

Trigger: Calling Device.GetNamedSize on a target/head (e.g. a unit test host, a non-standard platform, or a trimmed app) where IFontNamedSizeService has no DependencyService registration.

Common situations: Running in a test runner without platform services; using an obsolete API after trimming removed the platform assembly; custom host platforms that did not wire up font services.

Related errors


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