{"record":{"id":"453528519e0fc3f3","repo":"microsoft/autogen","slug":"input-must-be-a-protobuf-message","errorCode":null,"errorMessage":"Input must be a protobuf message.","messagePattern":"Input must be a protobuf message\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/Core.Grpc/ProtobufTypeNameResolver.cs","lineNumber":20,"sourceCode":"// ProtobufTypeNameResolver.cs\n\nusing Google.Protobuf;\n\nnamespace Microsoft.AutoGen.Core.Grpc;\n\npublic class ProtobufTypeNameResolver : ITypeNameResolver\n{\n    public string ResolveTypeName(Type input)\n    {\n        if (typeof(IMessage).IsAssignableFrom(input))\n        {\n            // TODO: Consider changing this to avoid instantiation...\n            var protoMessage = (IMessage?)Activator.CreateInstance(input) ?? throw new InvalidOperationException($\"Failed to create instance of {input.FullName}\");\n            return protoMessage.Descriptor.FullName;\n        }\n        else\n        {\n            throw new ArgumentException(\"Input must be a protobuf message.\");\n        }\n    }\n}\n","sourceCodeStart":2,"sourceCodeEnd":24,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/Core.Grpc/ProtobufTypeNameResolver.cs#L2-L24","documentation":"Thrown by ProtobufTypeNameResolver.ResolveTypeName when the input Type does not implement Google.Protobuf.IMessage. The resolver exists only to produce protobuf full type names (Descriptor.FullName), so non-proto types are rejected with an ArgumentException.","triggerScenarios":"Calling ResolveTypeName(typeof(SomePoco)) or passing an interface/non-message class; wiring ProtobufTypeNameResolver as the global ITypeNameResolver in a mixed proto/POCO system.","commonSituations":"Registering the protobuf resolver too broadly in DI so it resolves names for JSON messages too; scanning assemblies and feeding every exported type to the resolver.","solutions":["Only resolve type names for protobuf-generated message types with this resolver","Route non-proto types to a different ITypeNameResolver implementation (e.g. one returning the CLR full name)","Guard call sites with typeof(IMessage).IsAssignableFrom(t) before invoking"],"exampleFix":"// before\nvar name = protobufResolver.ResolveTypeName(typeof(MyDto));\n\n// after\nvar name = typeof(IMessage).IsAssignableFrom(typeof(MyDto))\n    ? protobufResolver.ResolveTypeName(typeof(MyDto))\n    : clrResolver.ResolveTypeName(typeof(MyDto));","handlingStrategy":"type-guard","validationCode":"if (!typeof(IMessage).IsAssignableFrom(input)) throw new ArgumentException($\"{input.FullName} is not a protobuf message; use a CLR type-name resolver\");","typeGuard":"static bool IsProtobufType(Type t) => typeof(Google.Protobuf.IMessage).IsAssignableFrom(t);","tryCatchPattern":"try { return protobufResolver.ResolveTypeName(type); } catch (ArgumentException) { return clrResolver.ResolveTypeName(type); }","preventionTips":["Dispatch to the correct ITypeNameResolver by message encoding","Do not register the protobuf resolver as the global resolver in mixed systems"],"tags":["protobuf","type-resolution","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}