microsoft/autogen · error · InvalidOperationException
Failed to create instance of {input.FullName}
Error message
Failed to create instance of {input.FullName} What it means
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.
Source
Thrown at dotnet/src/Microsoft.AutoGen/Core.Grpc/ProtobufTypeNameResolver.cs:15
// Copyright (c) Microsoft Corporation. All rights reserved.
// ProtobufTypeNameResolver.cs
using Google.Protobuf;
namespace Microsoft.AutoGen.Core.Grpc;
public class ProtobufTypeNameResolver : ITypeNameResolver
{
public string ResolveTypeName(Type input)
{
if (typeof(IMessage).IsAssignableFrom(input))
{
// TODO: Consider changing this to avoid instantiation...
var protoMessage = (IMessage?)Activator.CreateInstance(input) ?? throw new InvalidOperationException($"Failed to create instance of {input.FullName}");
return protoMessage.Descriptor.FullName;
}
else
{
throw new ArgumentException("Input must be a protobuf message.");
}
}
}
View on GitHub (pinned to 027ecf0a37)
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
Example fix
// before
public class MyMessage : IMessage { public MyMessage(Dep dep) {...} } // no parameterless ctor
// after
public class MyMessage : IMessage { public MyMessage() {} public MyMessage(Dep dep) : this() {...} } Defensive patterns
Strategy: validation
Validate before calling
if (input.IsAbstract || input.GetConstructor(Type.EmptyTypes) is null) throw new ArgumentException($"{input.FullName} needs a public parameterless constructor"); Type guard
static bool IsInstantiableProtobuf(Type t) => typeof(IMessage).IsAssignableFrom(t) && !t.IsAbstract && t.GetConstructor(Type.EmptyTypes) is not null;
Try / catch
try { return resolver.ResolveTypeName(type); } catch (InvalidOperationException ex) when (ex.Message.Contains("Failed to create instance")) { return type.FullName; } Prevention
- Only feed protobuf codegen types to the resolver
- Exclude abstract types from assembly scans
When it happens
Trigger: 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.
Common situations: Custom hand-written IMessage wrappers instead of codegen'd classes; DI-injected message types with constructor parameters; abstract types picked up by assembly scanning.
Related errors
- Input must be a protobuf message.
- Could not create chat manager
- Could not create chat manager; make sure that it contains a
- Response is null.
- Unexpected message '{message}'.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/192cc80404336ce8.
Report an issue: GitHub.