{"record":{"id":"beab3c20a9c0e035","repo":"XINCGer/Unity3DTraining","slug":"cannot-read-from-property","errorCode":null,"errorMessage":"Cannot read from property","messagePattern":"Cannot read from property","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/OneofAccessor.cs","lineNumber":52,"sourceCode":"using System.Reflection;\n// using Google.Protobuf.Compatibility;\n\nnamespace Google.Protobuf.Reflection\n{\n    /// <summary>\n    /// Reflection access for a oneof, allowing clear and \"get case\" actions.\n    /// </summary>\n    public sealed class OneofAccessor\n    {\n        private readonly Func<IMessage, int> caseDelegate;\n        private readonly Action<IMessage> clearDelegate;\n        private OneofDescriptor descriptor;\n\n        internal OneofAccessor(PropertyInfo caseProperty, MethodInfo clearMethod, OneofDescriptor descriptor)\n        {\n            if (!caseProperty.CanRead)\n            {\n                throw new ArgumentException(\"Cannot read from property\");\n            }\n            this.descriptor = descriptor;\n            caseDelegate = ReflectionUtil.CreateFuncIMessageT<int>(caseProperty.GetGetMethod());\n\n            this.descriptor = descriptor;\n            clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod);\n        }\n\n        /// <summary>\n        /// Gets the descriptor for this oneof.\n        /// </summary>\n        /// <value>\n        /// The descriptor of the oneof.\n        /// </value>\n        public OneofDescriptor Descriptor { get { return descriptor; } }\n\n        /// <summary>\n        /// Clears the oneof in the specified message.","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/OneofAccessor.cs#L34-L70","documentation":"OneofAccessor's constructor requires the CLR case-discriminator property (e.g. 'MyOneofCase') to be readable, since it binds a getter delegate used to determine which oneof field is set. If PropertyInfo.CanRead is false it throws ArgumentException. This indicates a mismatch between the generated message type and the descriptor wiring.","triggerScenarios":"Constructing a OneofAccessor directly (or via OneofDescriptor.CreateAccessor) with a PropertyInfo for the oneof case property that is write-only or otherwise unreadable.","commonSituations":"Custom reflection tooling building accessors over generated protobuf classes, or generated code whose case property was replaced/hidden by partial-class shadowing.","solutions":["Use the standard generated message classes so the Case property has a public getter.","Pass the property obtained via ClrType.GetProperty(name + \"Case\") on the generated type rather than an unrelated property.","Regenerate the C# code with protoc so case properties match the descriptor."],"exampleFix":"// before\nvar prop = typeof(Msg).GetProperty(\"Choice\", BindingFlags.NonPublic | BindingFlags.SetProperty);\nnew OneofAccessor(prop, clearMethod, oneofDesc); // throws\n// after\nvar prop = typeof(Msg).GetProperty(\"ChoiceCase\"); // readable generated case property\nnew OneofAccessor(prop, clearMethod, oneofDesc);","handlingStrategy":"validation","validationCode":"var prop = typeof(Msg).GetProperty(oneofName + \"Case\");\nif (prop == null || !prop.CanRead) throw new InvalidOperationException($\"Readable '{oneofName}Case' property required\");","typeGuard":"bool IsReadableOneofCase(PropertyInfo p) => p != null && p.CanRead;","tryCatchPattern":"try { accessor = new OneofAccessor(prop, clearMethod, desc); } catch (ArgumentException ex) { log.Error($\"Bad oneof property: {ex.Message}\"); throw; }","preventionTips":["Only construct accessors from standard protoc-generated message types.","Check PropertyInfo.CanRead before constructing reflection accessors."],"tags":["protobuf","reflection","oneof"],"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"}