XINCGer/Unity3DTraining · error · DescriptorValidationException
Method Clear not found in
Error message
Method Clear{clrName} not found in {containingType.ClrType} What it means
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.
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).
Example fix
// before
// class missing ClearChoice()
// after
public void ClearChoice() { caseField_ = 0; choice_ = null; } Defensive patterns
Strategy: validation
Validate before calling
if (typeof(Msg).GetMethod("Clear" + oneofName) == null)
throw new InvalidOperationException($"{typeof(Msg)} lacks Clear{oneofName}(); regenerate protobuf code"); Try / catch
try { BuildGeneratedTypes(); } catch (DescriptorValidationException ex) { log.Error($"Missing oneof clear method: {ex.Message}"); throw; } Prevention
- Keep Google.Protobuf runtime and protoc versions aligned.
- If implementing IMessage manually, always add both '<Name>Case' property and 'Clear<Name>()' for each oneof.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Property Case not found in
- FieldDescriptorProto.oneof_index is out of range for type
- Cannot read from property
- Multiple values specified for oneof
- Invalid type specified
AI-assisted analysis of XINCGer/Unity3DTraining@016f98412e (2026-09-12).
Data as JSON: /api/errors/b207fe7e92aa968a.
Report an issue: GitHub.
Appendix: source
Thrown at NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Reflection/OneofDescriptor.cs:116
if (field.ContainingOneof == this)
{
fieldCollection.Add(field);
}
}
fields = new ReadOnlyCollection<FieldDescriptor>(fieldCollection);
}
private OneofAccessor CreateAccessor(string clrName)
{
var caseProperty = containingType.ClrType.GetProperty(clrName + "Case");
if (caseProperty == null)
{
throw new DescriptorValidationException(this, "Property " + clrName + "Case not found in " + containingType.ClrType);
}
var clearMethod = containingType.ClrType.GetMethod("Clear" + clrName);
if (clearMethod == null)
{
throw new DescriptorValidationException(this, "Method Clear" + clrName + " not found in " + containingType.ClrType);
}
return new OneofAccessor(caseProperty, clearMethod, this);
}
}
}
View on GitHub (pinned to 016f98412e)