{"record":{"id":"f320fbdc41b88edd","repo":"microsoft/autogen","slug":"value-cannot-be-null-parameter-param-parametert","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'param.ParameterType')","messagePattern":"Value cannot be null\\. \\(Parameter 'param\\.ParameterType'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI/Extension/FunctionContractExtension.cs","lineNumber":31,"sourceCode":"{\n    /// <summary>\n    /// Convert a <see cref=\"FunctionContract\"/> to a <see cref=\"ChatTool\"/> that can be used in gpt funciton call.\n    /// </summary>\n    /// <param name=\"functionContract\">function contract</param>\n    /// <returns><see cref=\"ChatTool\"/></returns>\n    public static ChatTool ToChatTool(this FunctionContract functionContract)\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 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);\n        propertySchemaBuilder = propertySchemaBuilder.Required(requiredParameterNames);\n\n        var option = new System.Text.Json.JsonSerializerOptions()","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI/Extension/FunctionContractExtension.cs#L13-L49","documentation":"ArgumentNullException ('param.ParameterType') thrown by ToChatTool when a function parameter has a null ParameterType. The extension must call JsonSchemaBuilder.FromType(param.ParameterType), which requires a concrete System.Type to generate the parameter's JSON schema.","triggerScenarios":"A FunctionParameter with ParameterType == null inside a FunctionContract passed to ToChatTool — typically from reflection over generic/obfuscated code or hand-constructed contracts missing the type.","commonSituations":"Hand-built FunctionContract objects; custom TypeReflector replacements; methods with dynamic/COM parameters where reflection yields null types; partially-initialized contract objects.","solutions":["Always set ParameterType when constructing FunctionParameter (e.g. typeof(string))","Prefer TypeReflector.GetFunctionContract so types come from real method metadata","Validate the contract (null-check Name and ParameterType for every parameter) before calling ToChatTool"],"exampleFix":"// before\nnew FunctionParameter { Name = \"city\", ParameterType = null }\n// ToChatTool -> ArgumentNullException\n\n// after\nnew FunctionParameter { Name = \"city\", ParameterType = typeof(string), IsRequired = true }","handlingStrategy":"validation","validationCode":"foreach (var p in contract.Parameters ?? [])\n{\n    if (p.ParameterType is null) throw new ArgumentException($\"Parameter '{p.Name}' of '{contract.Name}' has no type\");\n}","typeGuard":"static bool ContractHasTypedParameters(FunctionContract c) => (c.Parameters ?? []).All(p => p.ParameterType is not null);","tryCatchPattern":"catch (ArgumentNullException ex) when (ex.ParamName == \"param.ParameterType\") { /* set ParameterType and rebuild tool */ }","preventionTips":["Always set ParameterType when authoring FunctionParameter","Use TypeReflector for reflection-based contracts","Validate contracts before ToChatTool"],"tags":["autogen","dotnet","openai","function-calling","function-contract","null-reference"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}