{"record":{"id":"ac70ee9369f3a24e","repo":"PrismLibrary/Prism","slug":"resources-propertysupport-expressionnotproperty-exception","errorCode":null,"errorMessage":"Resources.PropertySupport_ExpressionNotProperty_Exception","messagePattern":"Resources\\.PropertySupport_ExpressionNotProperty_Exception","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Mvvm/PropertySupport.cs","lineNumber":54,"sourceCode":"        /// <param name=\"expression\">The LambdaExpression</param>\n        /// <returns>The name of the property.</returns>\n        /// <exception cref=\"ArgumentNullException\">Thrown if the <paramref name=\"expression\"/> is null.</exception>\n        /// <exception cref=\"ArgumentException\">Thrown when the expression is:<br/>\n        ///     The <see cref=\"MemberExpression\"/> does not represent a property.<br/>\n        ///     Or, the property is static.\n        /// </exception>\n        internal static string? ExtractPropertyNameFromLambda(LambdaExpression expression)\n        {\n            if (expression == null)\n                throw new ArgumentNullException(nameof(expression));\n\n            var memberExpression = expression.Body as MemberExpression;\n            if (memberExpression == null)\n                throw new ArgumentException(Resources.PropertySupport_NotMemberAccessExpression_Exception, nameof(expression));\n\n            var property = memberExpression.Member as PropertyInfo;\n            if (property == null)\n                throw new ArgumentException(Resources.PropertySupport_ExpressionNotProperty_Exception, nameof(expression));\n\n            var getMethod = property.GetMethod;\n            if (getMethod.IsStatic)\n                throw new ArgumentException(Resources.PropertySupport_StaticExpression_Exception, nameof(expression));\n\n            return memberExpression.Member.Name;\n        }\n\n    }\n}\n","sourceCodeStart":36,"sourceCodeEnd":65,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Mvvm/PropertySupport.cs#L36-L65","documentation":"ExtractPropertyNameFromLambda throws ArgumentException with PropertySupport_ExpressionNotProperty_Exception when the lambda body is a member access but that member is a FieldInfo rather than a PropertyInfo. Prism only supports properties, since the helper is meant for PropertyChanged scenarios.","triggerScenarios":"Passing () => someField (a public field, not a property) to PropertySupport.ExtractPropertyName.","commonSituations":"Legacy codebases with public fields used where properties belong; structs/DTOs exposing fields; interop types surfaced as fields (e.g. COM interop or compiler-generated backing fields).","solutions":["Convert the field to a property and pass () => instance.PropertyName","Use nameof(fieldName) if you genuinely need a field's name — nameof requires no expression","If you cannot change the type, wrap the field in a property first"],"exampleFix":"// before\npublic string Name; // field\nvar name = PropertySupport.ExtractPropertyName(() => instance.Name); // throws\n// after\npublic string Name { get; set; } // property\nvar name = PropertySupport.ExtractPropertyName(() => instance.Name); // ok","handlingStrategy":"validation","validationCode":"if (expr.Body is MemberExpression me && me.Member is not PropertyInfo)\n    throw new ArgumentException(\"Use a property, not a field, in the expression\");","typeGuard":"bool IsFieldAccess<T>(Expression<Func<T>> expr) =>\n    (expr?.Body as MemberExpression)?.Member is FieldInfo;","tryCatchPattern":"try\n{\n    var name = PropertySupport.ExtractPropertyName(() => obj.Name);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogError(ex, \"Expression must target a property, not a field\");\n}","preventionTips":["Replace public fields with auto-properties (migrates transparently)","Avoid passing compiler-generated or interop fields to expression helpers","Document that Prism's helper supports properties only"],"tags":["argumentexception","field-vs-property","expression","mvvm","prism"],"backgroundTag":"invalid-argument-value","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}