microsoft/autogen · error · InvalidOperationException
Parameter name cannot be null
Error message
Parameter name cannot be null
What it means
While converting a FunctionContract to a Mistral FunctionDefinition, each parameter must produce a named JSON-schema property; a FunctionContract parameter whose Name is null cannot become a property key and this InvalidOperationException is thrown.
Source
Thrown at dotnet/src/AutoGen.Mistral/Extension/FunctionContractExtension.cs:29
public static class FunctionContractExtension
{
/// <summary>
/// Convert a <see cref="FunctionContract"/> to a <see cref="FunctionDefinition"/> that can be used in funciton call.
/// </summary>
/// <param name="functionContract">function contract</param>
/// <returns><see cref="FunctionDefinition"/></returns>
public static FunctionDefinition ToMistralFunctionDefinition(this FunctionContract functionContract)
{
var functionDefinition = new FunctionDefinition(functionContract.Name ?? throw new Exception("Function name cannot be null"), functionContract.Description ?? throw new Exception("Function description cannot be null"));
var requiredParameterNames = new List<string>();
var propertiesSchemas = new Dictionary<string, JsonSchema>();
var propertySchemaBuilder = new JsonSchemaBuilder().Type(SchemaValueType.Object);
foreach (var param in functionContract.Parameters ?? [])
{
if (param.Name is null)
{
throw new InvalidOperationException("Parameter name cannot be null");
}
var schemaBuilder = new JsonSchemaBuilder().FromType(param.ParameterType ?? throw new ArgumentNullException(nameof(param.ParameterType)));
if (param.Description != null)
{
schemaBuilder = schemaBuilder.Description(param.Description);
}
if (param.IsRequired)
{
requiredParameterNames.Add(param.Name);
}
var schema = schemaBuilder.Build();
propertiesSchemas[param.Name] = schema;
}
propertySchemaBuilder = propertySchemaBuilder.Properties(propertiesSchemas);View on GitHub (pinned to 027ecf0a37)
Solutions
- Ensure every parameter in FunctionContract.Parameters has a non-null Name matching the method signature.
- Use reflection-based contract generation instead of manual construction so names are always populated.
- Validate contracts before registration (guard loop) to fail with a better error message.
Example fix
// before
var contract = new FunctionContract
{
Name = "GetWeather",
Parameters = [new FunctionParameterContract { Description = "city", ParameterType = typeof(string) }],
};
// after
var contract = new FunctionContract
{
Name = "GetWeather",
Parameters = [new FunctionParameterContract { Name = "city", Description = "city", ParameterType = typeof(string), IsRequired = true }],
}; Defensive patterns
Strategy: validation
Validate before calling
var badParams = (contract.Parameters ?? []).Where(p => string.IsNullOrEmpty(p.Name)).ToList();
if (badParams.Count > 0) throw new ArgumentException($"{contract.Name}: {badParams.Count} parameter(s) missing Name"); Type guard
static bool AllParametersNamed(FunctionContract c) => (c.Parameters ?? []).All(p => !string.IsNullOrEmpty(p.Name));
Prevention
- Always set Name on FunctionParameterContract
- Use FromType/FromMethod-based builders
- Validate contracts before ToMistralFunctionDefinition
When it happens
Trigger: Registering a tool whose parameter list contains a FunctionContract parameter with Name == null — typically hand-built contracts, partially initialized parameter objects, or parameter metadata extraction that returned null.
Common situations: Manually constructing FunctionContract.Parameters and omitting Name; refactoring that drops the name assignment; edge cases in reflection-based contract providers (e.g. weird parameter expressions).
Related errors
- Function name cannot be null
- Missing MISTRAL_API_KEY environment variable
- Failed to review code block
- Missing MISTRAL_API_KEY environment variable.
- Please set OPENAI_API_KEY environment variable.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/3477a0e818de795e.
Report an issue: GitHub.