OrchardCMS/OrchardCore · error · ArgumentException

Invalid geo point representation

Error message

Invalid geo point representation

What it means

TryGetPointFromJToken accepts a geo point as either an object with latitude/longitude (or lat/lon) properties, or a two-element numeric array [lon, lat]. Any other representation hits the default case and throws 'Invalid geo point representation'.

Solutions

  1. Use the supported forms: {"latitude":52.1,"longitude":4.9} (or lat/lon) or [4.9, 52.1].
  2. Ensure the array has exactly two numeric elements in [longitude, latitude] order.
  3. Remove string ('lat,lon') or geo-hash point encodings, which are not supported.

Example fix

// before
{"geo_distance":{"distance":"10km","location":"52.1,4.9"}}
// after
{"geo_distance":{"distance":"10km","location":{"latitude":52.1,"longitude":4.9}}}
Defensive patterns

Strategy: validation

Validate before calling

bool IsValidPoint(JsonNode? p) =>
    p is JsonObject o && (o.ContainsKey("latitude") || o.ContainsKey("lat"))
    || p is JsonArray a && a.Count == 2 && a.All(x => x is JsonValue);
if (!IsValidPoint(node)) throw new ArgumentException("Geo point must be {latitude,longitude} or [lon,lat].");

Type guard

static bool IsGeoPoint(JsonNode? n) => n is JsonObject o && (o.ContainsKey("latitude") || o.ContainsKey("lat")) || n is JsonArray { Count: 2 };

Try / catch

try { var q = geoProvider.CreateFilteredQuery(builder, ctx, name, node); }
catch (ArgumentException ex) when (ex.Message == "Invalid geo point representation") { /* normalize and retry */ }

Prevention

When it happens

Trigger: Passing a point as a string like "lat,lon", a single number, an object missing lat/lon keys, or an array with non-numeric/incorrect-length values that fall through.

Common situations: Copying geo_point syntax from Elasticsearch (which also accepts strings and geo hash), or mistyping latitude/Longitude property names.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/c346f49d9ac5c4de. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/GeoDistanceFilterProvider.cs:204

                if (!geoPointValue.ContainsKey("lon") || !geoPointValue.ContainsKey("lat"))
                {
                    return false;
                }

                point = new Point(geoPointValue["lon"].Value<double>(), geoPointValue["lat"].Value<double>(), ctx);
                return true;
            case JsonValueKind.Array:
                var geoArrayValue = geoToken.AsArray();

                if (geoArrayValue.Count != 2)
                {
                    return false;
                }

                point = new Point(geoArrayValue[0].Value<double>(), geoArrayValue[1].Value<double>(), ctx);

                return true;
            default: throw new ArgumentException("Invalid geo point representation");
        }
    }

    [GeneratedRegex(@"^((\d+(\.\d*)?)|(\.\d+))")]
    private static partial Regex StringDistanceRegex();
}

View on GitHub (pinned to 4306c0717f)