{"record":{"id":"041110ae8f118eb5","repo":"XINCGer/Unity3DTraining","slug":"unexpected-case-in-struct-field","errorCode":null,"errorMessage":"Unexpected case in struct field: ","messagePattern":"Unexpected case in struct field: ","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonFormatter.cs","lineNumber":618,"sourceCode":"\n            switch (specifiedField.FieldNumber)\n            {\n                case Value.BoolValueFieldNumber:\n                case Value.StringValueFieldNumber:\n                case Value.NumberValueFieldNumber:\n                    WriteValue(writer, value);\n                    return;\n                case Value.StructValueFieldNumber:\n                case Value.ListValueFieldNumber:\n                    // Structs and ListValues are nested messages, and already well-known types.\n                    var nestedMessage = (IMessage)specifiedField.Accessor.GetValue(message);\n                    WriteWellKnownTypeValue(writer, nestedMessage.Descriptor, nestedMessage);\n                    return;\n                case Value.NullValueFieldNumber:\n                    WriteNull(writer);\n                    return;\n                default:\n                    throw new InvalidOperationException(\"Unexpected case in struct field: \" + specifiedField.FieldNumber);\n            }\n        }\n\n        internal void WriteList(TextWriter writer, IList list)\n        {\n            writer.Write(\"[ \");\n            bool first = true;\n            foreach (var value in list)\n            {\n                if (!first)\n                {\n                    writer.Write(PropertySeparator);\n                }\n                WriteValue(writer, value);\n                first = false;\n            }\n            writer.Write(first ? \"]\" : \" ]\");\n        }","sourceCodeStart":600,"sourceCodeEnd":636,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonFormatter.cs#L600-L636","documentation":"JsonFormatter.WriteStructFieldValue throws InvalidOperationException when the Value message's selected oneof field has an unrecognized field number. This is an internal exhaustiveness check: the switch covers the six known Value cases and anything else indicates corrupted or foreign descriptors.","triggerScenarios":"Formatting a Value whose descriptor comes from a mismatched/modified descriptor set so the oneof case resolves to a non-standard field number; mixing generated code with an incompatible Google.Protobuf runtime.","commonSituations":"Version skew between protoc-generated code and the runtime library; hand-built or rewritten descriptors; binary incompatibility after protobuf schema edits to Value.","solutions":["Regenerate code and keep the Google.Protobuf NuGet package version aligned with protoc","Do not modify generated descriptors","Verify the message is a genuine google.protobuf.Value, not a similarly named custom type","Upgrade all projects to the same protobuf runtime version"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static bool IsKnownValueCase(Value v) => v.KindCase == Value.KindOneofCase.NullValue || v.KindCase == Value.KindOneofCase.NumberValue || v.KindCase == Value.KindOneofCase.StringValue || v.KindCase == Value.KindOneofCase.BoolValue || v.KindCase == Value.KindOneofCase.StructValue || v.KindCase == Value.KindOneofCase.ListValue;","tryCatchPattern":"try { json = formatter.Format(msg); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Unexpected case in struct field\")) { /* fix version skew between generated code and runtime */ }","preventionTips":["Keep protoc and Google.Protobuf runtime versions aligned","Never alter generated descriptors","Verify Struct/Value types are the official well-known types"],"tags":["csharp","protobuf","json","struct"],"backgroundTag":"internal-invariant-violation","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"}