{"record":{"id":"b9c786da530ac5c3","repo":"XINCGer/Unity3DTraining","slug":"invalid-field-mask-to-be-converted-to-json-first","errorCode":null,"errorMessage":"Invalid field mask to be converted to JSON: {firstInvalid}","messagePattern":"Invalid field mask to be converted to JSON: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs","lineNumber":78,"sourceCode":"            {\n                var writer = new StringWriter();\n                var query = paths.Select<string, string>(JsonFormatter.ToJsonName);\n                JsonFormatter.WriteString(writer, string.Join(\",\", query.ToArray()));\n                return writer.ToString();\n            }\n            else\n            {\n                if (diagnosticOnly)\n                {\n                    var writer = new StringWriter();\n                    writer.Write(\"{ \\\"@warning\\\": \\\"Invalid FieldMask\\\", \\\"paths\\\": \");\n                    JsonFormatter.Default.WriteList(writer, (IList)paths);\n                    writer.Write(\" }\");\n                    return writer.ToString();\n                }\n                else\n                {\n                    throw new InvalidOperationException(\"Invalid field mask to be converted to JSON: \" + firstInvalid);\n                }\n            }\n        }\n\n        /// <summary>\n        /// Checks whether the given path is valid for a field mask.\n        /// </summary>\n        /// <returns>true if the path is valid; false otherwise</returns>\n        private static bool ValidatePath(string input)\n        {\n            for (int i = 0; i < input.Length; i++)\n            {\n                char c = input[i];\n                if (c >= 'A' && c <= 'Z')\n                {\n                    return false;\n                }\n                if (c == '_' && i < input.Length - 1)","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs#L60-L96","documentation":"FieldMask.ToJson validates that every path in the mask is a valid lowercase snake_case field path (validating conversion). If any path contains characters invalid for JSON field-mask representation (e.g. CamelCase segments that would need camel-conversion but are invalid), it throws InvalidOperationException naming the first invalid path. Field masks in JSON must use camelCase, and the library requires paths it can validate before converting.","triggerScenarios":"Calling ToDiagnosticString()/ToJson() on a FieldMask whose Paths contain entries like 'FooBar' or paths with invalid characters, so IsValidPath/validating conversion fails and firstInvalid holds the offending path.","commonSituations":"Building field masks from C# property names (PascalCase) instead of protobuf field names; hand-writing paths with typos; masks constructed programmatically from user input; mixing camelCase and snake_case when copying from JSON examples.","solutions":["Convert paths to valid snake_case protobuf field names before adding them (FieldMask.Util.ToUpperCamelCase is for output; input must be lowercase snake_case)","Use FieldMask.ForFieldNames or construct from reflection-derived protobuf field names rather than raw strings","Fix the specific path named in the exception message","If interop requires camelCase input, normalize with a snake_case converter before adding to Paths"],"exampleFix":"// before\nvar mask = new FieldMask();\nmask.Paths.Add(\"DisplayName\"); // invalid\nvar s = mask.ToDiagnosticString(); // throws\n// after\nvar mask2 = new FieldMask();\nmask2.Paths.Add(\"display_name\");\nvar s2 = mask2.ToDiagnosticString(); // \"displayName\"","handlingStrategy":"validation","validationCode":"static bool IsValidFieldMaskPath(string p) => !string.IsNullOrEmpty(p) && p.All(c => char.IsLower(c) || char.IsDigit(c) || c == '_' || c == '.');","typeGuard":"static bool IsUsableFieldMask(FieldMask m) => m != null && m.Paths.Count > 0 && m.Paths.All(IsValidFieldMaskPath);","tryCatchPattern":"try { return mask.ToDiagnosticString(); } catch (InvalidOperationException ex) { log.Warn(ex, \"Invalid field mask\"); return string.Join(\",\", mask.Paths); }","preventionTips":["Store protobuf field names (snake_case), not C# property names","Derive paths from field descriptors instead of hard-coded strings","Test masks against the JSON round-trip in unit tests"],"tags":["protobuf","c-sharp","fieldmask","serialization"],"backgroundTag":"invalid-argument-format","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"}