microsoft/autogen · error · ArgumentNullException
modelName is a required property for LMStudioConfig and cann
Error message
modelName is a required property for LMStudioConfig and cannot be null
What it means
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).
Source
Thrown at dotnet/src/AutoGen/LMStudioConfig.cs:23
using System.ClientModel;
using OpenAI;
using OpenAI.Chat;
namespace AutoGen;
/// <summary>
/// Add support for consuming openai-like API from LM Studio
/// </summary>
public class LMStudioConfig : ILLMConfig
{
public LMStudioConfig(string host, int port, string modelName)
{
this.Host = host;
this.Port = port;
this.Uri = new Uri($"http://{host}:{port}/v1");
if (modelName == null)
{
throw new ArgumentNullException("modelName is a required property for LMStudioConfig and cannot be null");
}
this.ModelName = modelName;
}
public LMStudioConfig(Uri uri, string modelName)
{
this.Uri = uri;
this.Host = uri.Host;
this.Port = uri.Port;
if (modelName == null)
{
throw new ArgumentNullException("modelName is a required property for LMStudioConfig and cannot be null");
}
this.ModelName = modelName;
}
public string Host { get; }
View on GitHub (pinned to 027ecf0a37)
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
Example fix
// before
var cfg = new LMStudioConfig("localhost", 1234, Environment.GetEnvironmentVariable("LM_MODEL")); // null if unset
// after
var model = Environment.GetEnvironmentVariable("LM_MODEL") ?? throw new InvalidOperationException("LM_MODEL is not set");
var cfg = new LMStudioConfig("localhost", 1234, model); Defensive patterns
Strategy: validation
Validate before calling
var modelName = config["LMStudio:ModelName"] as string;
if (string.IsNullOrWhiteSpace(modelName)) throw new InvalidOperationException("LMStudio:ModelName is required");
var cfg = new LMStudioConfig(host, port, modelName); Try / catch
catch (ArgumentNullException ex) when (ex.Message.Contains("modelName")) { throw new ConfigurationException("LM Studio model name is missing; set it in configuration", ex); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Value cannot be null. (Parameter 'array')
- The recent update is not a TextMessage
- The content has more than one choice. Please try another inp
- Invalid ChatResponseMessage
- Invalid message type: {m.GetType().Name}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/b7b56148729e7707.
Report an issue: GitHub.