{"record":{"id":"6d75dd694c1569c7","repo":"ppy/osu","slug":"attempting-to-use-this-setter-will-not-work-correc","errorCode":null,"errorMessage":"Attempting to use this setter will not work correctly. Use specific init-only properties exposed by {nameof(LegacySpriteText)} instead.","messagePattern":"Attempting to use this setter will not work correctly\\. Use specific init-only properties exposed by (.+?) instead\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"osu.Game/Skinning/LegacySpriteText.cs","lineNumber":38,"sourceCode":"        public const char PP_SUFFIX_CHAR = '\\uebd9';\r\n\r\n        public Vector2? MaxSizePerGlyph { get; init; }\r\n        public bool FixedWidth { get; init; }\r\n\r\n        private readonly LegacyFont font;\r\n\r\n        private LegacyGlyphStore glyphStore = null!;\r\n\r\n        protected override char FixedWidthReferenceCharacter => '5';\r\n\r\n        protected override char[] FixedWidthExcludeCharacters => new[] { ',', '.', '%', 'x', PP_SUFFIX_CHAR };\r\n\r\n        // ReSharper disable once UnusedMember.Global\r\n        // being unused is the point here\r\n        public new FontUsage Font\r\n        {\r\n            get => base.Font;\r\n            set => throw new InvalidOperationException(@\"Attempting to use this setter will not work correctly. \"\r\n                                                       + $@\"Use specific init-only properties exposed by {nameof(LegacySpriteText)} instead.\");\r\n        }\r\n\r\n        public LegacySpriteText(LegacyFont font)\r\n        {\r\n            this.font = font;\r\n\r\n            Shadow = false;\r\n            UseFullGlyphHeight = false;\r\n        }\r\n\r\n        [BackgroundDependencyLoader]\r\n        private void load(ISkinSource skin)\r\n        {\r\n            string fontPrefix = skin.GetFontPrefix(font);\r\n            base.Font = new FontUsage(fontPrefix, 1, fixedWidth: FixedWidth);\r\n            Spacing = new Vector2(-skin.GetFontOverlap(font), 0);\r\n\r","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/ppy/osu/blob/d9c73e12adff2feaae4a3e158d36fe5883faf6ca/osu.Game/Skinning/LegacySpriteText.cs#L20-L56","documentation":"Thrown by the Font setter on LegacySpriteText, which is intentionally shadowed (new) to hard-block callers from using the inherited SpriteText.Font property. LegacySpriteText derives its font entirely from the LegacyFont passed to its constructor plus its init-only properties, so the inherited setter would silently do nothing useful.","triggerScenarios":"Calling spriteText.Font = new FontUsage(...) on a LegacySpriteText instance, or via XAML/builder code that sets the inherited Font property generically.","commonSituations":"Generic code that sets Font on any SpriteText (e.g. a style applier) running against a LegacySpriteText; porting component code from SpriteText to LegacySpriteText without updating the font configuration.","solutions":["Do not set Font on LegacySpriteText; instead set its init-only properties (FontFace, Size, etc.) or construct it with the correct LegacyFont.","Type-check before applying a generic Font: if (text is LegacySpriteText lst) { /* use init-only props */ } else { text.Font = font; }.","Refactor generic font appliers to go through an abstraction that LegacySpriteText implements differently."],"exampleFix":"// before\ntext.Font = new FontUsage(\"Arial\", 20f);\n\n// after (LegacySpriteText)\nvar lst = (LegacySpriteText)text;\n// configure via constructor or init-only props, e.g.:\nlst.Size = 20f; // or whatever init-only property applies","handlingStrategy":"type-guard","validationCode":"if (text is LegacySpriteText)\n    throw new InvalidOperationException(\"LegacySpriteText does not accept Font setter; use init-only props.\");","typeGuard":"static bool IsLegacySpriteText(SpriteText t) => t is LegacySpriteText;","tryCatchPattern":"try { text.Font = font; }\ncatch (InvalidOperationException) { /* apply via legacy-specific path */ }","preventionTips":["Type-check SpriteText before applying a generic Font.","Configure LegacySpriteText via constructor/init-only properties only.","Drive font configuration through an abstraction LegacySpriteText implements differently."],"tags":["skinning","sprite-text","api-misuse","font"],"backgroundTag":null,"analyzedSha":"d9c73e12adff2feaae4a3e158d36fe5883faf6ca","analyzedAt":"2026-08-13T14:12:54.015Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}