{"record":{"id":"192cc80404336ce8","repo":"microsoft/autogen","slug":"failed-to-create-instance-of-input-fullname","errorCode":null,"errorMessage":"Failed to create instance of {input.FullName}","messagePattern":"Failed to create instance of (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/Core.Grpc/ProtobufTypeNameResolver.cs","lineNumber":15,"sourceCode":"// Copyright (c) Microsoft Corporation. All rights reserved.\n// 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":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/Core.Grpc/ProtobufTypeNameResolver.cs#L1-L24","documentation":"Thrown by ProtobufTypeNameResolver.ResolveTypeName when Activator.CreateInstance(input) returns null for a type that implements IMessage. The resolver instantiates the message solely to read its Descriptor.FullName; failure means the type lacks a public parameterless constructor or its constructor threw.","triggerScenarios":"Passing a protobuf message type with a non-public or parameterized-only constructor; a custom IMessage implementation whose constructor throws (e.g. missing runtime dependencies); abstract IMessage subtype passed as input.","commonSituations":"Custom hand-written IMessage wrappers instead of codegen'd classes; DI-injected message types with constructor parameters; abstract types picked up by assembly scanning.","solutions":["Ensure the message type has a public parameterless constructor (standard protobuf codegen provides one)","Use protobuf-generated message classes rather than custom IMessage implementations","Filter abstract types and interfaces out of any scanning logic that feeds ResolveTypeName"],"exampleFix":"// before\npublic class MyMessage : IMessage { public MyMessage(Dep dep) {...} } // no parameterless ctor\n\n// after\npublic class MyMessage : IMessage { public MyMessage() {} public MyMessage(Dep dep) : this() {...} }","handlingStrategy":"validation","validationCode":"if (input.IsAbstract || input.GetConstructor(Type.EmptyTypes) is null) throw new ArgumentException($\"{input.FullName} needs a public parameterless constructor\");","typeGuard":"static bool IsInstantiableProtobuf(Type t) => typeof(IMessage).IsAssignableFrom(t) && !t.IsAbstract && t.GetConstructor(Type.EmptyTypes) is not null;","tryCatchPattern":"try { return resolver.ResolveTypeName(type); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Failed to create instance\")) { return type.FullName; }","preventionTips":["Only feed protobuf codegen types to the resolver","Exclude abstract types from assembly scans"],"tags":["protobuf","reflection","type-resolution"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}