{"record":{"id":"612530c86eaa6f3c","repo":"stride3d/stride","slug":"font-fontname-with-style-style-is-already-registered-with","errorCode":null,"errorMessage":"Font '{fontName}' with style '{style}' is already registered with path '{existing.FilePath}'. Cannot register a different path '{filePath}' for the same font name and style.","messagePattern":"Font '(.+?)' with style '(.+?)' is already registered with path '(.+?)'\\. Cannot register a different path '(.+?)' for the same font name and style\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Font/RuntimeFontProvider.cs","lineNumber":60,"sourceCode":"    /// <param name=\"filePath\">The absolute or relative path to the .ttf file.</param>\n    /// <param name=\"style\">The font style.</param>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"fontName\"/> is null or empty.</exception>\n    /// <exception cref=\"FileNotFoundException\">Thrown when the font file does not exist.</exception>\n    /// <exception cref=\"InvalidOperationException\">Thrown when attempting to register the same font name and style with a different file path.</exception>\n    public void RegisterFont(string fontName, string filePath, FontStyle style = FontStyle.Regular)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(fontName);\n\n        if (!File.Exists(filePath))\n            throw new FileNotFoundException($\"Font file not found: {filePath}\", filePath);\n\n        var key = FontHelper.GetFontPath(fontName, style);\n\n        if (registeredFonts.TryGetValue(key, out var existing))\n        {\n            if (existing.FilePath == filePath) return;\n\n            throw new InvalidOperationException(\n                $\"Font '{fontName}' with style '{style}' is already registered with path '{existing.FilePath}'. \" +\n                $\"Cannot register a different path '{filePath}' for the same font name and style.\");\n        }\n\n        fontSystem.FontManager.LoadFontFromFileSystem(fontName, filePath, style);\n\n        registeredFonts[key] = new RuntimeFontInfo(fontName, filePath, style);\n    }\n\n    /// <summary>\n    /// Checks if a font is registered for runtime loading.\n    /// </summary>\n    /// <param name=\"fontName\">The font name.</param>\n    /// <param name=\"style\">The font style.</param>\n    /// <returns>True if registered, false otherwise.</returns>\n    public bool IsRegistered(string fontName, FontStyle style = FontStyle.Regular)\n    {\n        return registeredFonts.ContainsKey(FontHelper.GetFontPath(fontName, style));","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Font/RuntimeFontProvider.cs#L42-L78","documentation":"RegisterFont keys fonts by (fontName, style); if that key already maps to a different file path, the method throws InvalidOperationException rather than silently re-pointing the font. Registering the same path again is a no-op (early return), so only genuine conflicts throw.","triggerScenarios":"Calling RegisterFont twice for the same fontName/style with different filePath values, e.g. re-registering after a config change or registering dev and release variants of the same family.","commonSituations":"Application startup code executed twice (double initialization); switching font file locations between versions without unregistering; two modules each registering their own copy of the same font family/style.","solutions":["Register each (fontName, style) pair exactly once; guard registration with a checked flag or if (!registeredFonts.ContainsKey(...)) equivalent check","Use a different fontName for the second path if both variants must coexist","Reuse the existing registration (same path is a safe no-op) instead of passing a new path","Catch InvalidOperationException and log it instead of failing startup if re-registration is benign in your app"],"exampleFix":"// before\nfontProvider.RegisterFont(\"UI\", \"assets/UIFont-v2.ttf\"); // already registered with v1\n// after\nif (!fontProvider.IsRegistered(\"UI\", FontStyle.Regular))\n    fontProvider.RegisterFont(\"UI\", \"assets/UIFont-v2.ttf\");","handlingStrategy":"validation","validationCode":"if (registered.ContainsKey((fontName, style)) && registered[(fontName, style)] != filePath)\n    log.Warn($\"Font {fontName}/{style} re-registered with different path; skipping\");\nelse\n    fontProvider.RegisterFont(fontName, filePath, style);","typeGuard":null,"tryCatchPattern":"try { fontProvider.RegisterFont(name, path, style); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"already registered\"))\n{\n    log.Warn($\"Ignoring duplicate font registration: {ex.Message}\");\n}","preventionTips":["Register fonts once in a single, idempotent initialization path","Track registrations in your own dictionary before calling RegisterFont","Use distinct font names for distinct file variants"],"tags":["fonts","conflict","registration"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}