{"record":{"id":"3477a0e818de795e","repo":"microsoft/autogen","slug":"parameter-name-cannot-be-null-3477a0","errorCode":null,"errorMessage":"Parameter name cannot be null","messagePattern":"Parameter name cannot be null","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Mistral/Extension/FunctionContractExtension.cs","lineNumber":29,"sourceCode":"\npublic static class FunctionContractExtension\n{\n    /// <summary>\n    /// Convert a <see cref=\"FunctionContract\"/> to a <see cref=\"FunctionDefinition\"/> that can be used in funciton call.\n    /// </summary>\n    /// <param name=\"functionContract\">function contract</param>\n    /// <returns><see cref=\"FunctionDefinition\"/></returns>\n    public static FunctionDefinition ToMistralFunctionDefinition(this FunctionContract functionContract)\n    {\n        var functionDefinition = new FunctionDefinition(functionContract.Name ?? throw new Exception(\"Function name cannot be null\"), functionContract.Description ?? throw new Exception(\"Function description cannot be null\"));\n        var requiredParameterNames = new List<string>();\n        var propertiesSchemas = new Dictionary<string, JsonSchema>();\n        var propertySchemaBuilder = new JsonSchemaBuilder().Type(SchemaValueType.Object);\n        foreach (var param in functionContract.Parameters ?? [])\n        {\n            if (param.Name is null)\n            {\n                throw new InvalidOperationException(\"Parameter name cannot be null\");\n            }\n\n            var schemaBuilder = new JsonSchemaBuilder().FromType(param.ParameterType ?? throw new ArgumentNullException(nameof(param.ParameterType)));\n            if (param.Description != null)\n            {\n                schemaBuilder = schemaBuilder.Description(param.Description);\n            }\n\n            if (param.IsRequired)\n            {\n                requiredParameterNames.Add(param.Name);\n            }\n\n            var schema = schemaBuilder.Build();\n            propertiesSchemas[param.Name] = schema;\n\n        }\n        propertySchemaBuilder = propertySchemaBuilder.Properties(propertiesSchemas);","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Mistral/Extension/FunctionContractExtension.cs#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nvar contract = new FunctionContract\n{\n    Name = \"GetWeather\",\n    Parameters = [new FunctionParameterContract { Description = \"city\", ParameterType = typeof(string) }],\n};\n\n// after\nvar contract = new FunctionContract\n{\n    Name = \"GetWeather\",\n    Parameters = [new FunctionParameterContract { Name = \"city\", Description = \"city\", ParameterType = typeof(string), IsRequired = true }],\n};","handlingStrategy":"validation","validationCode":"var badParams = (contract.Parameters ?? []).Where(p => string.IsNullOrEmpty(p.Name)).ToList();\nif (badParams.Count > 0) throw new ArgumentException($\"{contract.Name}: {badParams.Count} parameter(s) missing Name\");","typeGuard":"static bool AllParametersNamed(FunctionContract c) => (c.Parameters ?? []).All(p => !string.IsNullOrEmpty(p.Name));","tryCatchPattern":null,"preventionTips":["Always set Name on FunctionParameterContract","Use FromType/FromMethod-based builders","Validate contracts before ToMistralFunctionDefinition"],"tags":["mistral","function-calling","parameters","null-check"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}