{"record":{"id":"b806a689b850f124","repo":"XINCGer/Unity3DTraining","slug":"not-all-required-properties-methods-available","errorCode":null,"errorMessage":"Not all required properties/methods available","messagePattern":"Not all required properties/methods available","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/SingleFieldAccessor.cs","lineNumber":56,"sourceCode":"{\n    /// <summary>\n    /// Accessor for single fields.\n    /// </summary>\n    internal sealed class SingleFieldAccessor : FieldAccessorBase\n    {\n        // All the work here is actually done in the constructor - it creates the appropriate delegates.\n        // There are various cases to consider, based on the property type (message, string/bytes, or \"genuine\" primitive)\n        // and proto2 vs proto3 for non-message types, as proto3 doesn't support \"full\" presence detection or default\n        // values.\n\n        private readonly Action<IMessage, object> setValueDelegate;\n        private readonly Action<IMessage> clearDelegate;\n\n        internal SingleFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor)\n        {\n            if (!property.CanWrite)\n            {\n                throw new ArgumentException(\"Not all required properties/methods available\");\n            }\n            setValueDelegate = ReflectionUtil.CreateActionIMessageObject(property.GetSetMethod());\n\n            var clrType = property.PropertyType;\n\n            // TODO: Validate that this is a reasonable single field? (Should be a value type, a message type, or string/ByteString.)\n            object defaultValue =\n                descriptor.FieldType == FieldType.Message ? null\n                : clrType == typeof(string) ? \"\"\n                : clrType == typeof(ByteString) ? ByteString.Empty\n                : Activator.CreateInstance(clrType);\n            clearDelegate = message => SetValue(message, defaultValue);\n        }\n\n        public override void Clear(IMessage message)\n        {\n            clearDelegate(message);\n        }","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/SingleFieldAccessor.cs#L38-L74","documentation":"SingleFieldAccessor requires the wrapped CLR property to be writable so it can bind a setter delegate (and the base class requires it readable). If PropertyInfo.CanWrite is false the constructor throws ArgumentException. It reflects a mismatch between the property being wrapped and a real generated protobuf single (non-repeated) field.","triggerScenarios":"Constructing SingleFieldAccessor (directly or via FieldDescriptor accessor creation) with a get-only property — e.g. read-only computed properties, map/repeated fields exposed read-only, or properties from a hand-written IMessage implementation lacking setters.","commonSituations":"Wrapping properties of read-only view types or protos generated with settings that expose collections without setters, in custom reflection/serialization tooling.","solutions":["Wrap only genuine generated single-field properties, which have public getters and setters.","If the class is hand-written, add a public setter to the property.","Use RepeatedFieldAccessor/MapFieldAccessor for repeated or map fields instead of SingleFieldAccessor."],"exampleFix":"// before\npublic string Name => name_; // get-only, throws\n// after\npublic string Name { get { return name_; } set { name_ = value ?? \"\"; } }","handlingStrategy":"validation","validationCode":"if (prop == null || !prop.CanRead || !prop.CanWrite)\n    throw new InvalidOperationException($\"Property {prop?.Name} must be readable and writable for SingleFieldAccessor\");","typeGuard":"bool IsWritableField(PropertyInfo p) => p != null && p.CanRead && p.CanWrite;","tryCatchPattern":"try { accessor = new SingleFieldAccessor(prop, desc); } catch (ArgumentException ex) { log.Error($\"Field accessor requires writable property: {ex.Message}\"); throw; }","preventionTips":["Only wrap protoc-generated single-field properties (they always have setters).","Route repeated/map fields to their dedicated accessor classes."],"tags":["protobuf","reflection","property-not-writable"],"backgroundTag":"invalid-argument-value","analyzedSha":"016f98412ea5e11756b286736f479b66ab6216d5","analyzedAt":"2026-09-12T01:08:58.711Z","contentChangedAt":"2026-09-12T01:08:58.711Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}