{"record":{"id":"dc647e8a4d34c076","repo":"XINCGer/Unity3DTraining","slug":"invalid-type-argument-requested-for-wrapper-codec","errorCode":null,"errorMessage":"Invalid type argument requested for wrapper codec: ","messagePattern":"Invalid type argument requested for wrapper codec: ","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/FieldCodec.cs","lineNumber":288,"sourceCode":"                { typeof(long), ForInt64(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) },\n                { typeof(uint), ForUInt32(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) },\n                { typeof(ulong), ForUInt64(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) },\n                { typeof(float), ForFloat(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Fixed32)) },\n                { typeof(double), ForDouble(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Fixed64)) },\n                { typeof(string), ForString(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.LengthDelimited)) },\n                { typeof(ByteString), ForBytes(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.LengthDelimited)) }\n            };\n\n            /// <summary>\n            /// Returns a field codec which effectively wraps a value of type T in a message.\n            /// \n            /// </summary>\n            internal static FieldCodec<T> GetCodec<T>()\n            {\n                object value;\n                if (!Codecs.TryGetValue(typeof(T), out value))\n                {\n                    throw new InvalidOperationException(\"Invalid type argument requested for wrapper codec: \" + typeof(T));\n                }\n                return (FieldCodec<T>)value;\n            }\n\n            internal static T Read<T>(CodedInputStream input, FieldCodec<T> codec)\n            {\n                int length = input.ReadLength();\n                int oldLimit = input.PushLimit(length);\n\n                uint tag;\n                T value = codec.DefaultValue;\n                while ((tag = input.ReadTag()) != 0)\n                {\n                    if (tag == codec.Tag)\n                    {\n                        value = codec.Read(input);\n                    }\n                    else","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/FieldCodec.cs#L270-L306","documentation":"WrapperFieldCodec.GetCodec<T> throws InvalidOperationException when T is not one of the supported wrapper value types registered in its static Codecs table. Only the protobuf primitive wrapper value types (e.g. Int32Value, StringValue, BoolValue, BytesValue) have codecs.","triggerScenarios":"Calling FieldCodec.Wrap<T> (GetCodec<T>) with a type argument that is not a Google.Protobuf.WellKnownTypes wrapper message, e.g. GetCodec<int> or a custom message type.","commonSituations":"Hand-writing FieldCodec instances for map/repeated wrapper fields with the wrong generic parameter; code generation mismatch between proto syntax (proto2 optional scalars) and runtime; reflection-driven code building codecs by Type.","solutions":["Use the corresponding wrapper message type (Int32Value, Int64Value, UInt32Value, UInt64Value, FloatValue, DoubleValue, BoolValue, StringValue, BytesValue) as T","Use the generated code's built-in codec instead of hand-constructing one","Wrap the raw value in the wrapper type before creating the codec","Regenerate code with matching Google.Protobuf runtime version"],"exampleFix":"// before\nvar codec = FieldCodec.Wrap<int>();\n// after\nvar codec = FieldCodec.Wrap<Int32Value>();","handlingStrategy":"type-guard","validationCode":"bool isWrapper = typeof(T) == typeof(Int32Value) || typeof(T) == typeof(Int64Value) || typeof(T) == typeof(UInt32Value) || typeof(T) == typeof(UInt64Value) || typeof(T) == typeof(FloatValue) || typeof(T) == typeof(DoubleValue) || typeof(T) == typeof(BoolValue) || typeof(T) == typeof(StringValue) || typeof(T) == typeof(BytesValue);","typeGuard":"static bool IsWrapperType(Type t) => typeof(IMessage).IsAssignableFrom(t) && t.FullName.StartsWith(\"Google.Protobuf.WellKnownTypes.\") && t.Name.EndsWith(\"Value\");","tryCatchPattern":"try { return FieldCodec.Wrap<T>(); } catch (InvalidOperationException) { throw new NotSupportedException($\"{typeof(T)} is not a wrapper value type\"); }","preventionTips":["Only use wrapper message types with FieldCodec.Wrap","Prefer generated codecs from message code","Keep generated code and runtime versions in sync"],"tags":["csharp","protobuf","generics"],"backgroundTag":"invalid-argument-value","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"}