{"record":{"id":"a674097a53396a41","repo":"devlooped/moq","slug":"property-0-1-does-not-have-a-getter","errorCode":null,"errorMessage":"Property {0}.{1} does not have a getter.","messagePattern":"Property (.+?)\\.(.+?) does not have a getter\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Moq/Guard.cs","lineNumber":231,"sourceCode":"                    string.Format(\n                        Resources.TypeNotMockable,\n                        type.GetFormattedName()));\n            }\n        }\n\n        public static void Positive(TimeSpan delay)\n        {\n            if (delay <= TimeSpan.Zero)\n            {\n                throw new ArgumentException(Resources.DelaysMustBeGreaterThanZero);\n            }\n        }\n\n        public static void CanRead(PropertyInfo property)\n        {\n            if (!property.CanRead(out _))\n            {\n                throw new ArgumentException(string.Format(\n                    CultureInfo.CurrentCulture,\n                    Resources.PropertyGetNotFound,\n                    property.DeclaringType!.Name, property.Name));\n            }\n        }\n\n        public static void CanWrite(PropertyInfo property)\n        {\n            if (!property.CanWrite(out _))\n            {\n                throw new ArgumentException(string.Format(\n                    CultureInfo.CurrentCulture,\n                    Resources.PropertySetNotFound,\n                    property.DeclaringType!.Name, property.Name));\n            }\n        }\n    }\n}","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/devlooped/moq/blob/89a5be629c752960fe403e95ff583e4ae6f00542/src/Moq/Guard.cs#L213-L249","documentation":"Moq throws this ArgumentException when setting up or verifying a property that has no getter (write-only property). Property setups like mock.Setup(m => m.Prop) require a readable property to intercept the get call.","triggerScenarios":"mock.Setup(m => m.WriteOnlyProp) or mock.VerifyGet(m => m.WriteOnlyProp) on a property that only defines a setter; also setup-property paths (SetupProperty) on getter-less properties.","commonSituations":"Mocking types with write-only properties (common in serialization/config sink types); after refactoring removed the getter; incorrect property chosen that is setter-only.","solutions":["Add a getter to the property on the mocked type if you control it.","Use SetupSet/VerifySet for setter-only properties instead of Setup/VerifyGet.","Track the value via a backing field captured in a callback on SetupSet, then assert on that field.","Mock an interface that exposes the property as read-write if available."],"exampleFix":"// before\nmock.Setup(m => m.Output).Returns(\"x\"); // Output is write-only\n// after\nmock.SetupSet(m => m.Output = It.IsAny<string>()).Callback(v => captured = v);","handlingStrategy":"type-guard","validationCode":"static bool HasGetter(Type t, string name) =>\n    t.GetProperty(name)?.GetGetMethod(nonPublic: false) != null;\n","typeGuard":"static bool IsReadable(System.Reflection.PropertyInfo p) => p.CanRead;\n","tryCatchPattern":"try { mock.Setup(expr).Returns(v); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"does not have a getter\"))\n{\n    // use SetupSet/VerifySet or add a getter to the property\n}\n","preventionTips":["Check PropertyInfo.CanRead before Setup/VerifyGet","Prefer read-write properties in mocked contracts","Use SetupSet for write-only properties","Review property refactorings that remove getters"],"tags":["moq","property","getter","setup"],"backgroundTag":"unsupported-operation","analyzedSha":"89a5be629c752960fe403e95ff583e4ae6f00542","analyzedAt":"2026-09-16T05:31:39.496Z","contentChangedAt":"2026-09-16T05:31:39.496Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}