{"record":{"id":"e5255aed3bff1a63","repo":"microsoft/autogen","slug":"function-name-cannot-be-null","errorCode":null,"errorMessage":"Function name cannot be null","messagePattern":"Function name cannot be null","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Mistral/Extension/FunctionContractExtension.cs","lineNumber":21,"sourceCode":"\nusing System;\nusing System.Collections.Generic;\nusing AutoGen.Core;\nusing Json.Schema;\nusing Json.Schema.Generation;\n\nnamespace AutoGen.Mistral.Extension;\n\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            {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Mistral/Extension/FunctionContractExtension.cs#L3-L39","documentation":"FunctionContractExtension.ToMistralFunctionDefinition converts an AutoGen FunctionContract (usually built from a .NET method via TypeProvideFunctionTools) into a Mistral FunctionDefinition, whose constructor requires a non-null name. A null functionContract.Name throws this generic Exception.","triggerScenarios":"Registering a function/tool whose FunctionContract has a null Name — e.g. a method whose name could not be resolved, a hand-built FunctionContract without Name, or a dynamically generated contract with missing metadata.","commonSituations":"Creating FunctionContract manually and forgetting Name; lambda/local methods or interop cases where the name extraction fails; null-propagating refactor of contract-building code.","solutions":["Set FunctionContract.Name (normally the method name) before converting.","Prefer the official reflection-based helpers (e.g. FunctionContract.FromMethod / TypeProvideFunctionTools) so name extraction is automatic.","Add a startup assertion over your tool list: any contract with null Name/Description fails fast with a clear message."],"exampleFix":"// before\nvar contract = new FunctionContract { Description = \"Gets weather\" };\nchatRequest.Tools = [contract.ToMistralFunctionDefinition()];\n\n// after\nvar contract = new FunctionContract { Name = nameof(GetWeather), Description = \"Gets weather\", Parameters = ... };\nchatRequest.Tools = [contract.ToMistralFunctionDefinition()];","handlingStrategy":"validation","validationCode":"foreach (var contract in functionContracts)\n{\n    if (string.IsNullOrEmpty(contract.Name)) throw new ArgumentException($\"Contract '{contract.Description}' has no Name\");\n}","typeGuard":"static bool HasValidName(FunctionContract c) => !string.IsNullOrEmpty(c.Name);","tryCatchPattern":null,"preventionTips":["Build contracts with reflection helpers instead of by hand","Assert Name/Description at tool-registration time","Unit-test contract generation for every exported tool"],"tags":["mistral","function-calling","tool-registration","null-check"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}