microsoft/autogen · error · InvalidDataException

Invalid semantic kernel settings in '{configFile}', please p

Error message

Invalid semantic kernel settings in '{configFile}', please provide configuration settings using instructions in the README.

What it means

Thrown when the settings JSON file exists but configuration.Get<KernelSettings>() returns null — i.e. the file parsed yet produced no bindable KernelSettings instance (typically an empty file, wrong JSON shape, or a root object whose properties do not match the KernelSettings keys). It tells you to fix the file contents per the README rather than create it.

Source

Thrown at dotnet/samples/dev-team/seed-memory/config/KernelSettings.cs:81

    /// <summary>
    /// Load the kernel settings from the specified configuration file if it exists.
    /// </summary>
    internal static KernelSettings FromFile(string configFile = DefaultConfigFile)
    {
        if (!File.Exists(configFile))
        {
            throw new FileNotFoundException($"Configuration not found: {configFile}");
        }

        var configuration = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile(configFile, optional: true, reloadOnChange: true)
            .AddEnvironmentVariables()
            .Build();

        return configuration.Get<KernelSettings>()
               ?? throw new InvalidDataException($"Invalid semantic kernel settings in '{configFile}', please provide configuration settings using instructions in the README.");
    }

    /// <summary>
    /// Load the kernel settings from user secrets.
    /// </summary>
    internal static KernelSettings FromUserSecrets()
    {
        var configuration = new ConfigurationBuilder()
            .AddUserSecrets<KernelSettings>()
            .AddEnvironmentVariables()
            .Build();

        return configuration.Get<KernelSettings>()
               ?? throw new InvalidDataException("Invalid semantic kernel settings in user secrets, please provide configuration settings using instructions in the README.");
    }
}

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Open the file and fill in real values matching the KernelSettings property names exactly (see the class in the same config folder).
  2. Ensure the JSON root object directly contains the settings keys — no extra wrapping section.
  3. Validate locally: var k = configuration.Get<KernelSettings>(); Debug.Assert(k is not null);
  4. If the file cannot hold secrets, move the values to user secrets and call FromUserSecrets() instead.

Example fix

// before
{ }

// after (match KernelSettings property names at the root)
{
  "Endpoint": "https://<res>.openai.azure.com/",
  "ApiKey": "<key>",
  "CompletionDeploymentOrModelId": "gpt-35-turbo",
  "EmbeddingDeploymentOrModelId": "text-embedding-ada-002"
}
Defensive patterns

Strategy: validation

Validate before calling

var settings = configuration.Get<KernelSettings>();
if (settings is null || string.IsNullOrWhiteSpace(settings.ApiKey))
{
    Console.Error.WriteLine("KernelSettings did not bind: check that the JSON root contains the expected keys (Endpoint, ApiKey, deployment ids).");
    return;
}

Type guard

static bool IsValidKernelSettings(KernelSettings? s) => s is not null && !string.IsNullOrWhiteSpace(s.Endpoint) && !string.IsNullOrWhiteSpace(s.ApiKey);

Try / catch

try { return configuration.Get<KernelSettings>() ?? throw new InvalidDataException(...); } catch (InvalidDataException) { /* print the expected key list from README and the keys actually present */ }

Prevention

When it happens

Trigger: appsettings.json exists but is empty ('{}' or blank); property names in the JSON don't match KernelSettings bindings (casing aside, wrong key names); JSON is an array or has the settings nested one level too deep so nothing binds at the root.

Common situations: Copy-pasted a config template from a different project; left the placeholder file from the repo in place; renamed KernelSettings properties between versions so old config files stop binding; nested the settings under a 'Kernel' section instead of the root.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/c395c69eb02f2971. Report an issue: GitHub.