{"record":{"id":"a40412c8e2d2b921","repo":"Unity-Technologies/UnityCsReference","slug":"get-function-cannot-be-null","errorCode":null,"errorMessage":"get function cannot be null","messagePattern":"get function cannot be null","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Inspector/GraphicsSettingsInspectors/GraphicsSettingsInspectorUtility.cs","lineNumber":28,"sourceCode":"using UnityEditor.Rendering;\nusing UnityEditor.Rendering.Settings;\nusing UnityEditor.UIElements;\nusing UnityEditor.UIElements.ProjectSettings;\nusing UnityEngine;\nusing UnityEngine.Rendering;\nusing UnityEngine.UIElements;\nusing Unity.Scripting.LifecycleManagement;\n\nnamespace UnityEditor.Inspector.GraphicsSettingsInspectors\n{\n    public static partial class GraphicsSettingsInspectorUtility\n    {\n        #region Localization\n\n        internal static void Localize(VisualElement visualElement, Func<VisualElement, string> get, Action<VisualElement, string> set)\n        {\n            if (get == null)\n                throw new InvalidOperationException(\"get function cannot be null\");\n            if (set == null)\n                throw new InvalidOperationException(\"set function cannot be null\");\n\n            var extractedText = get.Invoke(visualElement);\n            if (string.IsNullOrWhiteSpace(extractedText))\n                return;\n\n            var localizedString = L10n.Tr(extractedText);\n            set.Invoke(visualElement, localizedString);\n        }\n\n        internal static void LocalizeTooltip(VisualElement visualElement)\n        {\n            Localize(visualElement, e => e.tooltip, (e, s) => e.tooltip = s);\n        }\n\n        internal static void LocalizeText(Label visualElement)\n        {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Inspector/GraphicsSettingsInspectors/GraphicsSettingsInspectorUtility.cs#L10-L46","documentation":"GraphicsSettingsInspectorUtility.Localize takes a get delegate used to extract text from a VisualElement. A null get function throws InvalidOperationException immediately because the method cannot read the source text to localize.","triggerScenarios":"Calling Localize(visualElement, null, set) — passing a null Func<VisualElement,string> for the get parameter.","commonSituations":"Building a localize call dynamically and forgetting to supply the getter. Refactoring callers and dropping the lambda. Passing null where a lambda was expected due to a signature change.","solutions":["Always pass a non-null get lambda, e.g. e => e.text.","Null-check the delegate before calling Localize if it may be absent.","Use the convenience wrappers like LocalizeTooltip which supply the get/set lambdas for you."],"exampleFix":"// before\nLocalize(elem, null, (e, s) => e.text = s); // throws\n\n// after\nLocalize(elem, e => e.text, (e, s) => e.text = s);","handlingStrategy":"validation","validationCode":"if (get == null) throw new ArgumentNullException(nameof(get));\nGraphicsSettingsInspectorUtility.Localize(elem, get, set);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply a get lambda; use convenience wrappers like LocalizeTooltip when possible.","Null-check delegates assembled dynamically before calling Localize."],"tags":["graphics-settings","localization","null-argument","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}