TechnitiumSoftware/DnsServer · error · HttpApiClientException

Invalid JSON response was received.

Error message

Invalid JSON response was received.

What it means

HttpApiClient.CheckResponseStatus expects every API response JSON to carry a top-level 'status' field. This HttpApiClientException fires when the parsed root element has no 'status' property, meaning the server returned JSON that does not conform to the API contract (or returned an unrelated page). It is the baseline 'I cannot interpret this response' signal used by all API calls.

Source

Thrown at DnsServerCore.HttpApi/HttpApiClient.cs:118

        public void Dispose()
        {
            if (_disposed)
                return;

            _httpClient?.Dispose();

            _disposed = true;
            GC.SuppressFinalize(this);
        }

        #endregion

        #region private

        private static void CheckResponseStatus(JsonElement rootElement)
        {
            if (!rootElement.TryGetProperty("status", out JsonElement jsonStatus))
                throw new HttpApiClientException("Invalid JSON response was received.");

            string? status = jsonStatus.GetString()?.ToLowerInvariant();
            switch (status)
            {
                case "ok":
                    return;

                case "error":
                    {
                        Exception? innerException = null;

                        if (rootElement.TryGetProperty("innerErrorMessage", out JsonElement jsonInnerErrorMessage))
                            innerException = new HttpApiClientException(jsonInnerErrorMessage.GetString()!);

                        if (rootElement.TryGetProperty("errorMessage", out JsonElement jsonErrorMessage))
                        {
                            if (innerException is null)
                                throw new HttpApiClientException(jsonErrorMessage.GetString()!);

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Verify _serverUrl points at the Technitium DNS Server HTTP API root (e.g. https://dns.example.com).
  2. Inspect the raw response body (log httpResponse.Content) to see what was actually returned.
  3. Check for reverse proxies / load balancers intercepting the request and returning non-API content.
  4. Confirm the server version matches the HttpApiClient library version.
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    var stats = await client.GetDashboardStatsAsync(user);
}
catch (HttpApiClientException ex) when (ex.Message == "Invalid JSON response was received.")
{
    // log _serverUrl, inspect raw body separately; likely wrong endpoint/proxy
    logger.LogError("API returned non-conforming JSON from {Url}", serverUrl);
    throw;
}

Prevention

When it happens

Trigger: Any HttpApiClient method (LoginAsync, GetDashboardStatsAsync, etc.) receives an HTTP body whose JSON root lacks 'status'. Typical when the URL points at the wrong service, a proxy returns an HTML error page parsed as JSON, or the server is an incompatible/older version.

Common situations: Pointing _serverUrl at a non-DNS-Server host; a reverse proxy returning a 200 with an HTML login page; hitting a different major version of the DNS server with a different response schema; TLS interception rewriting the body.

Understand the failure class

Related errors


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