{"record":{"id":"ec9c5a22d5239eb5","repo":"AvaloniaUI/Avalonia","slug":"font-collection-key-should-follow-the-fonts-schem","errorCode":null,"errorMessage":"Font collection Key should follow the fonts: scheme.","messagePattern":"Font collection Key should follow the fonts: scheme\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/FontManager.cs","lineNumber":228,"sourceCode":"\n            glyphTypeface = null;\n\n            return false;\n        }\n\n        /// <summary>\n        /// Add a font collection to the manager.\n        /// </summary>\n        /// <param name=\"fontCollection\">The font collection.</param>\n        /// <exception cref=\"ArgumentException\"></exception>\n        /// <remarks>If a font collection's key is already present the collection is replaced.</remarks>\n        public void AddFontCollection(IFontCollection fontCollection)\n        {\n            var key = fontCollection.Key;\n\n            if (!fontCollection.Key.IsFontCollection())\n            {\n                throw new ArgumentException(\"Font collection Key should follow the fonts: scheme.\", nameof(fontCollection));\n            }\n\n            _fontCollections.AddOrUpdate(key, fontCollection, (_, oldCollection) =>\n            {\n                oldCollection.Dispose();\n\n                return fontCollection;\n            });\n        }\n\n        /// <summary>\n        /// Removes the font collection that corresponds to specified key.\n        /// </summary>\n        /// <param name=\"key\">The font collection's key.</param>\n        public void RemoveFontCollection(Uri key)\n        {\n            if (_fontCollections.TryRemove(key, out var fontCollection))\n            {","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/FontManager.cs#L210-L246","documentation":"FontManager.AddFontCollection throws ArgumentException when the font collection's Key URI does not use the 'fonts' scheme (FontCollectionScheme == \"fonts\"). Custom font collections must be registered under a 'fonts:' URI so the manager can route lookups correctly. The check uses UriExtensions.IsFontCollection which compares uri.Scheme == \"fonts\".","triggerScenarios":"Calling fontManager.AddFontCollection(collection) where collection.Key is a Uri whose Scheme is not exactly \"fonts\". E.g. Key = new Uri(\"http://...\", ...), new Uri(\"avares://...\", ...), or a relative URI.","commonSituations":"Implementing a custom IFontCollection and setting Key to a non-fonts scheme. Copy-pasting a URI scheme from another context. Misreading the contract and using the application asset scheme instead of 'fonts:'.","solutions":["Set the IFontCollection.Key to a URI with the 'fonts' scheme, e.g. new Uri(\"fonts:MyCollection\").","Verify uri.Scheme == \"fonts\" (FontManager.FontCollectionScheme) before calling AddFontCollection.","If wrapping built-in collections, follow the same Key convention used by SystemFonts (which uses a fonts: scheme)."],"exampleFix":"// before\ncollection.Key = new Uri(\"custom:MyFonts\", UriKind.Absolute);\nmanager.AddFontCollection(collection);\n\n// after\ncollection.Key = new Uri(\"fonts:MyFonts\", UriKind.Absolute);\nmanager.AddFontCollection(collection);","handlingStrategy":"validation","validationCode":"if (collection.Key.Scheme != FontManager.FontCollectionScheme) // \"fonts\"\n    throw new InvalidOperationException($\"Key scheme must be 'fonts', got '{collection.Key.Scheme}'.\");\nmanager.AddFontCollection(collection);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set IFontCollection.Key to a 'fonts:' scheme URI.","Use FontManager.FontCollectionScheme constant to build the key.","Validate the scheme in custom font collection constructors."],"tags":["font-manager","font-collection","uri","scheme","media"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}