{"record":{"id":"b207fe7e92aa968a","repo":"XINCGer/Unity3DTraining","slug":"method-clear-clrname-not-found-in-containingtype","errorCode":null,"errorMessage":"Method Clear{clrName} not found in {containingType.ClrType}","messagePattern":"Method Clear(.+?) not found in (.+?)","errorType":"validation","errorClass":"DescriptorValidationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/OneofDescriptor.cs","lineNumber":116,"sourceCode":"                if (field.ContainingOneof == this)\n                {\n                    fieldCollection.Add(field);\n                }\n            }\n            fields = new ReadOnlyCollection<FieldDescriptor>(fieldCollection);\n        }\n\n        private OneofAccessor CreateAccessor(string clrName)\n        {\n            var caseProperty = containingType.ClrType.GetProperty(clrName + \"Case\");\n            if (caseProperty == null)\n            {\n                throw new DescriptorValidationException(this, \"Property \" + clrName + \"Case not found in \" + containingType.ClrType);\n            }\n            var clearMethod = containingType.ClrType.GetMethod(\"Clear\" + clrName);\n            if (clearMethod == null)\n            {\n                throw new DescriptorValidationException(this, \"Method Clear\" + clrName + \" not found in \" + containingType.ClrType);\n            }\n\n            return new OneofAccessor(caseProperty, clearMethod, this);\n        }\n    }\n}\n","sourceCodeStart":98,"sourceCodeEnd":123,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/OneofDescriptor.cs#L98-L123","documentation":"The companion check in OneofDescriptor.CreateAccessor: after finding the '<clrName>Case' property it requires a 'Clear<clrName>()' method on the generated type to reset the oneof. Missing method throws DescriptorValidationException. This means the generated message class does not follow the standard oneof code-generation pattern.","triggerScenarios":"A generated (or hand-written) message type lacks the 'Clear<OneofName>()' method while the descriptor expects it — stale generated code, manual IMessage implementation, or a custom IGeneratedMessageType whose type was built without the clear method.","commonSituations":"Partial class declarations that accidentally shadow or remove the Clear method, or old generated code from a protoc version predating oneof support conventions being paired with a new runtime.","solutions":["Regenerate the C# code with a current protoc so 'Clear<Name>()' is emitted.","Add the missing public void Clear<Name>() method if the message class is hand-written.","Verify runtime and generated-code versions are compatible (Google.Protobuf package vs protoc output)."],"exampleFix":"// before\n// class missing ClearChoice()\n// after\npublic void ClearChoice() { caseField_ = 0; choice_ = null; }","handlingStrategy":"validation","validationCode":"if (typeof(Msg).GetMethod(\"Clear\" + oneofName) == null)\n    throw new InvalidOperationException($\"{typeof(Msg)} lacks Clear{oneofName}(); regenerate protobuf code\");","typeGuard":null,"tryCatchPattern":"try { BuildGeneratedTypes(); } catch (DescriptorValidationException ex) { log.Error($\"Missing oneof clear method: {ex.Message}\"); throw; }","preventionTips":["Keep Google.Protobuf runtime and protoc versions aligned.","If implementing IMessage manually, always add both '<Name>Case' property and 'Clear<Name>()' for each oneof."],"tags":["protobuf","reflection","oneof","descriptor-validation"],"backgroundTag":"schema-validation-failed","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"}