{"record":{"id":"6e3109b687486da7","repo":"dotnet/maui","slug":"the-current-platform-does-not-implement-the-ifontn","errorCode":null,"errorMessage":"The current platform does not implement the IFontNamedSizeService dependency service.","messagePattern":"The current platform does not implement the IFontNamedSizeService dependency service\\.","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/Device.cs","lineNumber":179,"sourceCode":"\t\tpublic static void StartTimer(TimeSpan interval, Func<bool> callback)\n\t\t{\n\t\t\t_ = callback ?? throw new ArgumentNullException(nameof(callback));\n\n\t\t\tvar dispatcher = Application.Current.FindDispatcher();\n\n\t\t\tdispatcher.StartTimer(interval, callback);\n\t\t}\n\n\t\t/// <summary>Returns the named font size for the specified element type.</summary>\n\t\t/// <param name=\"size\">The named size to retrieve.</param>\n\t\t/// <param name=\"targetElementType\">The element type to get the named size for.</param>\n\t\t/// <param name=\"useOldSizes\">Whether to use legacy font sizes.</param>\n\t\t/// <returns>The font size value.</returns>\n\t\t[Obsolete]\n\t\t[EditorBrowsable(EditorBrowsableState.Never)]\n\t\tpublic static double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes) =>\n\t\t\tDependencyService.Get<IFontNamedSizeService>()?.GetNamedSize(size, targetElementType, useOldSizes) ??\n\t\t\tthrow new NotImplementedException(\"The current platform does not implement the IFontNamedSizeService dependency service.\");\n\n\t\t[Obsolete]\n\t\tpublic static class Styles\n\t\t{\n\t\t\tpublic static readonly string TitleStyleKey = \"TitleStyle\";\n\n\t\t\tpublic static readonly string SubtitleStyleKey = \"SubtitleStyle\";\n\n\t\t\tpublic static readonly string BodyStyleKey = \"BodyStyle\";\n\n\t\t\tpublic static readonly string ListItemTextStyleKey = \"ListItemTextStyle\";\n\n\t\t\tpublic static readonly string ListItemDetailTextStyleKey = \"ListItemDetailTextStyle\";\n\n\t\t\tpublic static readonly string CaptionStyleKey = \"CaptionStyle\";\n\n\t\t\tpublic static readonly Style TitleStyle = new Style(typeof(Label)) { BaseResourceKey = TitleStyleKey };\n","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Device.cs#L161-L197","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Migrate off the obsolete Device.GetNamedSize to the non-obsolete overload or use explicit numeric font sizes.","On a custom platform, register an IFontNamedSizeService implementation via DependencyService.Register.","In test code, register a stub IFontNamedSizeService before invoking GetNamedSize."],"exampleFix":"// before\nvar size = Device.GetNamedSize(NamedSize.Medium, typeof(Label), useOldSizes: false);\n\n// after\nvar size = Device.GetNamedSize(NamedSize.Medium, typeof(Label)); // non-obsolete overload\n// or\nlabel.FontSize = 14;","handlingStrategy":"validation","validationCode":"// Check the service before calling the obsolete API.\nvar svc = DependencyService.Get<IFontNamedSizeService>();\nif (svc is null)\n    throw new InvalidOperationException(\"IFontNamedSizeService not registered on this platform.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer non-obsolete Device.GetNamedSize overloads or explicit FontSize.","On custom/test platforms, register an IFontNamedSizeService stub.","Avoid Device.GetNamedSize in headless/unit-test hosts."],"tags":["device","dependencyservice","font","platform","notimplemented","obsolete"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}