TechnitiumSoftware/DnsServer · error · ArgumentException

At least one parameter must be provided.

Error message

At least one parameter must be provided.

What it means

SetClusterSettingsAsync requires a non-empty dictionary of cluster parameters; sending nothing would be a no-op HTTP call. It throws ArgumentException when clusterParameters.Count == 0, before iterating keys or building the request. This is an argument-contract failure, not a server error.

Source

Thrown at DnsServerCore.HttpApi/HttpApiClient.cs:295

            using JsonDocument jsonDoc = await JsonDocument.ParseAsync(httpResponse.Content.ReadAsStream(cancellationToken), cancellationToken: cancellationToken);
            JsonElement rootElement = jsonDoc.RootElement;

            CheckResponseStatus(rootElement);

            DashboardStats? stats = rootElement.GetProperty("response").Deserialize<DashboardStats>(_serializerOptions);
            if (stats is null)
                throw new HttpApiClientException("Invalid JSON response was received.");

            return stats;
        }

        public async Task SetClusterSettingsAsync(string actingUsername, IReadOnlyDictionary<string, string> clusterParameters, CancellationToken cancellationToken = default)
        {
            if (!_loggedIn)
                throw new HttpApiClientException("No active session exists. Please login and try again.");

            if (clusterParameters.Count == 0)
                throw new ArgumentException("At least one parameter must be provided.", nameof(clusterParameters));

            foreach (KeyValuePair<string, string> parameter in clusterParameters)
            {
                switch (parameter.Key)
                {
                    case "token":
                    case "node":
                        throw new ArgumentException($"The '{parameter.Key}' is an invalid Settings parameter.", nameof(clusterParameters));
                }
            }

            HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post, new Uri(_serverUrl, $"api/settings/set?actingUser={Uri.EscapeDataString(actingUsername)}"));
            httpRequest.Content = new FormUrlEncodedContent(clusterParameters);

            HttpResponseMessage httpResponse = await _httpClient.SendAsync(httpRequest, cancellationToken);

            httpResponse.EnsureSuccessStatusCode();

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Populate clusterParameters with at least one valid key/value before calling.
  2. Skip the call entirely when the dictionary is empty rather than passing it.
  3. Add a unit assertion that the dictionary is non-empty in test fixtures.

Example fix

// before
var p = new Dictionary<string,string>();
await client.SetClusterSettingsAsync(user, p); // throws

// after
var p = new Dictionary<string,string> { ["enableLogging"] = "true" };
await client.SetClusterSettingsAsync(user, p);
Defensive patterns

Strategy: validation

Validate before calling

if (clusterParameters is null || clusterParameters.Count == 0)
    throw new ArgumentException(
        "Provide at least one cluster parameter before calling SetClusterSettingsAsync.",
        nameof(clusterParameters));

await client.SetClusterSettingsAsync(user, clusterParameters);

Type guard

static bool HasClusterParams(IReadOnlyDictionary<string, string> p)
    => p is not null && p.Count > 0;

Try / catch

catch (ArgumentException ex) when (ex.Message == "At least one parameter must be provided. (Parameter 'clusterParameters')")
{
    // nothing to send; treat as no-op or surface to caller
}

Prevention

When it happens

Trigger: Calling SetClusterSettingsAsync with an empty dictionary, or one that was filtered/cleared before the call.

Common situations: Building the parameter map conditionally and passing it through when no conditions matched; a config loader that produced zero entries; refactoring that left the dictionary uninitialized.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/11112c85602e6175. Report an issue: GitHub.