{"record":{"id":"4ebf64479257b146","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"selector-is-invalid-it-has-to-be-in-format-x-x","errorCode":null,"errorMessage":"Selector is invalid, it has to be in format x => x.Property","messagePattern":"Selector is invalid, it has to be in format x => x\\.Property","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/Localising/LocalisationExtensions.cs","lineNumber":25,"sourceCode":"using System.Collections.Generic;\nusing System.Linq;\nusing System.Linq.Expressions;\nusing System.Reflection;\n\nnamespace Klocman.Localising\n{\n    public static class LocalisationExtensions\n    {\n        private static readonly Dictionary<Enum, string> LocalisedEnumNameCache = new();\n\n        /// <summary>\n        ///     Get a fancy name of selected property or field\n        /// </summary>\n        public static string GetLocalisedMemberName<TContainer, TMember>(this TContainer instance,\n            Expression<Func<TContainer, TMember>> selector) where TContainer : class\n        {\n            if (selector.Body is not MemberExpression expression)\n                throw new ArgumentException(\"Selector is invalid, it has to be in format x => x.Property\");\n            \n            var member = expression.Member;\n            return GetLocalisedMemberName(member);\n        }\n\n        /// <summary>\n        ///     Get a fancy name of selected property or field\n        /// </summary>\n        public static string GetLocalisedMemberName<TContainer, TMember>(Expression<Func<TContainer, TMember>> selector) \n            where TContainer : class\n        {\n            if (selector.Body is not MemberExpression expression)\n                throw new ArgumentException(\"Selector is invalid, it has to be in format x => x.Property\");\n\n            var member = expression.Member;\n            return GetLocalisedMemberName(member);\n        }\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/Localising/LocalisationExtensions.cs#L7-L43","documentation":"Thrown by the instance extension GetLocalisedMemberName<TContainer,TMember>(this TContainer, Expression<Func<TContainer,TMember>> selector). It pattern-matches selector.Body against MemberExpression; anything that is not a direct member access (a property or field reference) is rejected with ArgumentException. The helper exists to extract a LocalisedNameAttribute from a member, so method calls, literals, unary/binary operators, and nested expressions are not valid.","triggerScenarios":"Passing a lambda whose body is not a bare member access: x => x.Compute(), x => 42, x => x.Name + x.Suffix, or x => SomeStatic.Property. Only x => x.Property or x => x.Field are accepted.","commonSituations":"Refactoring a property into a method (x => x.Name becomes x => x.GetName()), pointing the selector at a computed expression while building a localised display name, or copy-pasting a lambda from a LINQ Where clause.","solutions":["Change the selector to a simple property/field access: obj.GetLocalisedMemberName(x => x.PropertyName).","If you need a method's localised name, call the MemberInfo overload GetLocalisedMemberName(MemberInfo) with typeof(T).GetMethod(...).","Extract the member first then pass MemberInfo directly to the MemberInfo overload."],"exampleFix":"// before\nvar name = obj.GetLocalisedMemberName(x => x.GetDisplayName()); // throws\n\n// after\nvar name = obj.GetLocalisedMemberName(x => x.DisplayName);","handlingStrategy":"validation","validationCode":"// Reject selectors that are not simple member access before calling\nif (selector.Body is not MemberExpression)\n    throw new InvalidOperationException(\"Selector must be x => x.Property\");\nvar name = instance.GetLocalisedMemberName(selector);","typeGuard":"static bool IsMemberSelector<TC, TM>(Expression<Func<TC, TM>> sel)\n    => sel.Body is MemberExpression;","tryCatchPattern":null,"preventionTips":["Keep localisation selectors to a single property/field access; never inline logic.","Wrap selector construction in a helper that asserts the MemberExpression shape.","Review any refactor that converts a property to a method for affected selectors."],"tags":["reflection","expressions","localisation","csharp","kloctools"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}