{"record":{"id":"9d4db28475d3eb51","repo":"microsoft/autogen","slug":"param-parametertype-cannot-be-null","errorCode":null,"errorMessage":"param.ParameterType cannot be null","messagePattern":"param\\.ParameterType cannot be null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI.V1/Extension/FunctionContractExtension.cs","lineNumber":36,"sourceCode":"    /// <returns><see cref=\"FunctionDefinition\"/></returns>\n    public static FunctionDefinition ToOpenAIFunctionDefinition(this FunctionContract functionContract)\n    {\n        var functionDefinition = new FunctionDefinition\n        {\n            Name = functionContract.Name,\n            Description = functionContract.Description,\n        };\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 ArgumentException(\"param.ParameterType cannot be null\"));\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);\n        propertySchemaBuilder = propertySchemaBuilder.Required(requiredParameterNames);\n\n        var option = new System.Text.Json.JsonSerializerOptions()","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Extension/FunctionContractExtension.cs#L18-L54","documentation":"ToOpenAIFunctionDefinition throws ArgumentException when a FunctionContract parameter has a non-null Name but a null ParameterType. The schema builder needs a CLR type to derive the JSON schema for each property, and a null type cannot be mapped.","triggerScenarios":"A hand-built FunctionParameter with Name set but ParameterType left null; contract JSON deserialization where the type field was dropped; custom IFuntionContractTypeProvider implementations returning null types.","commonSituations":"Dynamic function registration where contracts are assembled at runtime; schema-driven tool definitions that carry only names and descriptions; upgrading AutoGen versions that changed how parameter types are resolved.","solutions":["Set ParameterType explicitly (e.g. typeof(string), typeof(int)) for every parameter","Derive contracts from actual .NET methods so ParameterType is populated automatically","Validate contracts before registration: assert Name != null && ParameterType != null for all parameters"],"exampleFix":"// before\nnew FunctionParameter { Name = \"city\" } // ParameterType null\n\n// after\nnew FunctionParameter { Name = \"city\", ParameterType = typeof(string), Description = \"City name\", IsRequired = true }","handlingStrategy":"validation","validationCode":"bool ContractTypesValid(FunctionContract c) =>\n    (c.Parameters ?? []).All(p => p.ParameterType is not null);","typeGuard":"static bool IsFullyTyped(FunctionContract c) =>\n    c.Parameters?.All(p => p.ParameterType is not null) ?? true;","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"ParameterType cannot be null\"))\n{\n    logger.LogError(\"Parameter {Param} of {Fn} lacks a type\", currentParam, fn.Name);\n    throw;\n}","preventionTips":["Always set ParameterType on hand-built parameters","Prefer reflection-based contract creation","Add schema smoke tests for every registered tool"],"tags":["openai","function-calling","function-contract","schema"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}