{"record":{"id":"b7b56148729e7707","repo":"microsoft/autogen","slug":"modelname-is-a-required-property-for-lmstudioconfi","errorCode":null,"errorMessage":"modelName is a required property for LMStudioConfig and cannot be null","messagePattern":"modelName is a required property for LMStudioConfig and cannot be null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen/LMStudioConfig.cs","lineNumber":23,"sourceCode":"using System.ClientModel;\nusing OpenAI;\nusing OpenAI.Chat;\n\nnamespace AutoGen;\n\n/// <summary>\n/// Add support for consuming openai-like API from LM Studio\n/// </summary>\npublic class LMStudioConfig : ILLMConfig\n{\n    public LMStudioConfig(string host, int port, string modelName)\n    {\n        this.Host = host;\n        this.Port = port;\n        this.Uri = new Uri($\"http://{host}:{port}/v1\");\n        if (modelName == null)\n        {\n            throw new ArgumentNullException(\"modelName is a required property for LMStudioConfig and cannot be null\");\n        }\n        this.ModelName = modelName;\n    }\n\n    public LMStudioConfig(Uri uri, string modelName)\n    {\n        this.Uri = uri;\n        this.Host = uri.Host;\n        this.Port = uri.Port;\n        if (modelName == null)\n        {\n            throw new ArgumentNullException(\"modelName is a required property for LMStudioConfig and cannot be null\");\n        }\n        this.ModelName = modelName;\n    }\n\n    public string Host { get; }\n","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen/LMStudioConfig.cs#L5-L41","documentation":"Thrown by the LMStudioConfig(host, port, modelName) constructor when modelName is null. LMStudioConfig requires a model name because LM Studio serves a specific loaded model per request path; the guard fires before any property is set, using ArgumentNullException (with the message as the paramName argument).","triggerScenarios":"Calling new LMStudioConfig(host, port, null) or new LMStudioConfig(host, port, modelName) where modelName came from configuration/environment that was unset and resolved to null.","commonSituations":"Reading ModelName from appsettings/environment and forgetting it in one environment (staging/prod), so it deserializes as null; building configs from user input where the model field was left blank; JSON deserialization of a config object without a modelName key.","solutions":["Provide a non-null modelName matching the model loaded in LM Studio (see the 'model' field in LM Studio's list-models response)","Fix the configuration source so ModelName cannot resolve to null (required setting, startup validation)","Guard at the call site: if (modelName is null) log a clear error about the missing setting before constructing the config"],"exampleFix":"// before\nvar cfg = new LMStudioConfig(\"localhost\", 1234, Environment.GetEnvironmentVariable(\"LM_MODEL\")); // null if unset\n// after\nvar model = Environment.GetEnvironmentVariable(\"LM_MODEL\") ?? throw new InvalidOperationException(\"LM_MODEL is not set\");\nvar cfg = new LMStudioConfig(\"localhost\", 1234, model);","handlingStrategy":"validation","validationCode":"var modelName = config[\"LMStudio:ModelName\"] as string;\nif (string.IsNullOrWhiteSpace(modelName)) throw new InvalidOperationException(\"LMStudio:ModelName is required\");\nvar cfg = new LMStudioConfig(host, port, modelName);","typeGuard":null,"tryCatchPattern":"catch (ArgumentNullException ex) when (ex.Message.Contains(\"modelName\")) { throw new ConfigurationException(\"LM Studio model name is missing; set it in configuration\", ex); }","preventionTips":["Treat the model name as a required setting and validate it at application startup","Use non-nullable typed options classes (with ValidateDataAnnotations) so nulls fail before reaching the constructor","Cross-check the value against LM Studio's /v1/models response when the app boots"],"tags":["autogen","lmstudio","config","null-check","csharp"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}