{"record":{"id":"323165aef082063b","repo":"Unity-Technologies/UnityCsReference","slug":"set-function-cannot-be-null","errorCode":null,"errorMessage":"set function cannot be null","messagePattern":"set function cannot be null","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Inspector/GraphicsSettingsInspectors/GraphicsSettingsInspectorUtility.cs","lineNumber":30,"sourceCode":"using 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        {\n            Localize(visualElement, e => ((Label)e).text, (e, s) => ((Label)e).text = s);\n        }","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Inspector/GraphicsSettingsInspectors/GraphicsSettingsInspectorUtility.cs#L12-L48","documentation":"Companion to error 354: Localize throws InvalidOperationException when the set Action<VisualElement,string> is null, because it would have no way to write the localized string back onto the element.","triggerScenarios":"Calling Localize(visualElement, get, null) — passing a null set delegate.","commonSituations":"Omitting the setter lambda when constructing a localize call. Misreading the parameter order and passing null for set.","solutions":["Always pass a non-null set lambda, e.g. (e, s) => e.text = s.","Prefer the typed convenience methods (LocalizeTooltip etc.) that wire both lambdas.","Null-check the delegate before calling if it is conditionally supplied."],"exampleFix":"// before\nLocalize(elem, e => e.text, null); // throws\n\n// after\nLocalize(elem, e => e.text, (e, s) => e.text = s);","handlingStrategy":"validation","validationCode":"if (set == null) throw new ArgumentNullException(nameof(set));\nGraphicsSettingsInspectorUtility.Localize(elem, get, set);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply a set lambda; prefer typed convenience localize helpers.","Verify parameter order (get before set) when refactoring callers."],"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"}