{"record":{"id":"0b3f442ab6e3cd92","repo":"stride3d/stride","slug":"text-spritefont","errorCode":null,"errorMessage":"text","messagePattern":"text","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/SpriteFont.cs","lineNumber":446,"sourceCode":"        /// <param name=\"fontSize\">The size of the font (ignored in the case of static fonts)</param>\n        /// <param name=\"length\">The length of the string to measure</param>\n        /// <returns>Vector2.</returns>\n        public Vector2 MeasureString([NotNull] StringBuilder text, Vector2 fontSize, int length)\n        {\n            return MeasureString(text, ref fontSize, length);\n        }\n\n        /// <summary>\n        /// Returns the width and height of the provided text for a given font size\n        /// </summary>\n        /// <param name=\"text\">The string to measure.</param>\n        /// <param name=\"fontSize\">The size of the font (ignored in the case of static fonts)</param>\n        /// <param name=\"length\">The length of the string to measure</param>\n        /// <returns>Vector2.</returns>\n        public Vector2 MeasureString([NotNull] string text, ref Vector2 fontSize, int length)\n        {\n            if (text == null)\n                throw new ArgumentNullException(nameof(text));\n\n            var proxy = new StringProxy(text, length);\n            return MeasureString(proxy, fontSize);\n        }\n\n        /// <summary>\n        /// Returns the width and height of the provided text for a given font size\n        /// </summary>\n        /// <param name=\"text\">The string to measure.</param>\n        /// <param name=\"fontSize\">The size of the font (ignored in the case of static fonts)</param>\n        /// <param name=\"length\">The length of the string to measure</param>\n        /// <returns>Vector2.</returns>\n        public Vector2 MeasureString([NotNull] StringBuilder text, ref Vector2 fontSize, int length)\n        {\n            if (text == null)\n                throw new ArgumentNullException(nameof(text));\n\n            var proxy = new StringProxy(text, length);","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/SpriteFont.cs#L428-L464","documentation":"SpriteFont.MeasureString(string, ref Vector2, int) throws ArgumentNullException when the text string is null. Measuring requires iterating the characters to compute the layout size; null is rejected at the entry point. An empty string is valid and yields a zero-size measurement.","triggerScenarios":"Calling MeasureString with a null string, e.g. measuring text loaded from a data source that returned null, or forwarding an optional UI label value before it is set.","commonSituations":"Localization lookup returning null for a missing key; measuring a player/ itemName that is null until data loads; computing layout for a label whose Text property was never initialized.","solutions":["Pass string.Empty for absent text — MeasureString(empty) returns a zero-size Vector2","Guard: if (text != null) var size = font.MeasureString(text, ...)","Coalesce with ?? string.Empty at the call site","Fix the text provider (localization, data binding) so it never returns null"],"exampleFix":"// before\nvar size = font.MeasureString(text, ref fontSize, text.Length); // text may be null\n// after\nvar size = font.MeasureString(text ?? string.Empty, ref fontSize, (text ?? string.Empty).Length);","handlingStrategy":"validation","validationCode":"var safeText = text ?? string.Empty;\nvar size = font.MeasureString(safeText, ref fontSize, safeText.Length);","typeGuard":"static bool CanMeasure(string s) => s != null;","tryCatchPattern":"try { size = font.MeasureString(text, ref fontSize, len); }\ncatch (ArgumentNullException) { size = Vector2.Zero; }","preventionTips":["Default all text sources to empty strings","Make localization providers return non-null values","Coalesce before measuring when text comes from data binding"],"tags":["csharp","null-argument","text-rendering","font"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}