{"record":{"id":"0d1711a1460d2727","repo":"XINCGer/Unity3DTraining","slug":"any-message-with-no-type","errorCode":null,"errorMessage":"Any message with no @type","messagePattern":"Any message with no @type","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":506,"sourceCode":"            var token = tokenizer.Next();\n            if (token.Type != JsonToken.TokenType.StartObject)\n            {\n                throw new InvalidProtocolBufferException(\"Expected object value for Any\");\n            }\n            int typeUrlObjectDepth = tokenizer.ObjectDepth;\n\n            // The check for the property depth protects us from nested Any values which occur before the type URL\n            // for *this* Any.\n            while (token.Type != JsonToken.TokenType.Name ||\n                token.StringValue != JsonFormatter.AnyTypeUrlField ||\n                tokenizer.ObjectDepth != typeUrlObjectDepth)\n            {\n                tokens.Add(token);\n                token = tokenizer.Next();\n\n                if (tokenizer.ObjectDepth < typeUrlObjectDepth)\n                {\n                    throw new InvalidProtocolBufferException(\"Any message with no @type\");\n                }\n            }\n\n            // Don't add the @type property or its value to the recorded token list\n            token = tokenizer.Next();\n            if (token.Type != JsonToken.TokenType.StringValue)\n            {\n                throw new InvalidProtocolBufferException(\"Expected string value for Any.@type\");\n            }\n            string typeUrl = token.StringValue;\n            string typeName = Any.GetTypeName(typeUrl);\n\n            MessageDescriptor descriptor = settings.TypeRegistry.Find(typeName);\n            if (descriptor == null)\n            {\n                throw new InvalidOperationException(\"Type registry has no descriptor for type name '\" + typeName + \"'\");\n            }\n","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L488-L524","documentation":"MergeAny buffers tokens while scanning for an \"@type\" property at the Any's own object depth. If the object closes (tokenizer.ObjectDepth drops below the recorded depth) before any @type key is found, the Any has no type URL, making the packed message unresolvable, so this InvalidProtocolBufferException is thrown.","triggerScenarios":"Parsing an Any field whose JSON object lacks an \"@type\" property entirely, e.g. {\"detail\": {\"id\": 42}}; or the @type key appears at a shallower depth than the Any's own object (misplaced key in a nested structure).","commonSituations":"Serializers that emit only the inner message fields for Any without @type; hand-written payloads where @type was renamed (e.g. \"type\" or \"typeUrl\") or dropped during field filtering; JSON schema validators that strip unknown @-prefixed keys.","solutions":["Include \"@type\": \"type.googleapis.com/<fully.qualified.TypeName>\" as a property of the Any JSON object.","Check sanitization/projection code that may strip the @type key before the payload reaches the parser.","Ensure @type is inside the Any's own object, not an enclosing or nested object.","Catch InvalidProtocolBufferException around Parse and reject payloads whose Any fields lack a type URL at ingress validation time."],"exampleFix":"// before: missing @type\n{\"detail\": {\"id\": 42}}\n\n// after\n{\"detail\": {\"@type\": \"type.googleapis.com/foo.Bar\", \"id\": 42}}","handlingStrategy":"validation","validationCode":"// @type must exist and be a string before parsing\nfunction hasTypeUrl(obj) {\n  return obj != null && typeof obj === 'object' && typeof obj['@type'] === 'string' && obj['@type'].length > 0;\n}","typeGuard":"function hasAtType(v) { return v !== null && typeof v === 'object' && typeof v['@type'] === 'string'; }","tryCatchPattern":"try { var msg = JsonParser.Default.Parse<T>(json); }\ncatch (InvalidProtocolBufferException ex) when (ex.Message == \"Any message with no @type\") { /* reject: Any lacks type URL */ }","preventionTips":["Check middleware/projection code for stripping '@'-prefixed keys","Keep @type inside the Any's own object at the correct nesting depth","Reject Any payloads without @type at the API boundary with a clear message"],"tags":["protobuf","json-parsing","any","missing-type-url"],"backgroundTag":"missing-required-argument","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"}